PDF生成ガイド
Report Flow APIを使用したPDF生成の詳細ガイドです。
概要
PDF生成には2つのモードがあります:
| モード | エンドポイント | レスポンス | 用途 |
|---|---|---|---|
| 同期生成 | /file/sync/single | PDFファイル | 即座に結果が必要な場合 |
| 非同期生成 | /file/async/single | ファイルURL | 大量生成やバックグラウンド処理 |
同期生成
基本的な使い方
curl -X POST https://api.re-port-flow.com/v1/file/sync/single \
-H "appkey: your-application-key" \
-H "Content-Type: application/json" \
-d '{
"designId": "550e8400-e29b-41d4-a716-446655440000",
"version": 1,
"content": {
"fileName": "invoice.pdf",
"params": {
"customerName": "山田太郎",
"invoiceNumber": "INV-2024-001",
"items": [
{
"name": "商品A",
"price": 1000,
"quantity": 2
}
]
}
}
}' \
--output invoice.pdf
レスポンスヘッダー
Content-Type: application/pdf
Content-Disposition: attachment; filename="invoice.pdf"
Content-Length: 123456
File-URL: https://re-port-flow.com/workspace-id/design/design-id/files/file-uuid
File-ID: file_abc123
JavaScript実装例
import axios from 'axios';
import fs from 'fs';
async function generatePDF(params) {
try {
const response = await axios.post(
'https://api.re-port-flow.com/v1/file/sync/single',
{
designId: params.designId,
version: params.version,
content: {
fileName: params.fileName,
params: params.data
}
},
{
headers: {
'appkey': process.env.APP_KEY,
'Content-Type': 'application/json'
},
responseType: 'arraybuffer'
}
);
// ファイルに保存
fs.writeFileSync(params.fileName, response.data);
// ファイルURLを取得
const fileUrl = response.headers['file-url'];
const fileId = response.headers['file-id'];
return { fileUrl, fileId };
} catch (error) {
console.error('PDF生成エラー:', error.response?.data || error.message);
throw error;
}
}
// 使用例
generatePDF({
designId: '550e8400-e29b-41d4-a716-446655440000',
version: 1,
fileName: 'invoice.pdf',
data: {
customerName: '山田太郎',
invoiceNumber: 'INV-2024-001',
items: [
{ name: '商品A', price: 1000, quantity: 2 }
]
}
});
非同期生成
大量のPDFを生成する場合や、タイムアウトを避けたい場合は非同期生成を使用します。
基本的な使い方
# 1. 生成リクエスト
curl -X POST https://api.re-port-flow.com/v1/file/async/single \
-H "appkey: your-application-key" \
-H "Content-Type: application/json" \
-d '{
"designId": "550e8400-e29b-41d4-a716-446655440000",
"version": 1,
"content": {
"fileName": "invoice.pdf",
"params": {...}
}
}'
# レスポンス例
{
"url": "https://re-port-flow.com/workspace-id/design/design-id/files/file-uuid",
"fileId": "file_abc123"
}