メインコンテンツへスキップ

ドキュメント生成(単一)

このエンドポイントの機能

PDF4me ドキュメント生成(単一) テンプレート (Word、 HTML、 または PDFデータペイロード付き(JSON、 XML、 または CSV1つに REST 呼び出し。テンプレートは Base64公的な URLまたは生 HTMLデータはインラインテキスト、 Base64-エンコードされたファイル、または URLレンダリングされたものを返します PDF、 Docx、 または HTML バイナリ(200)として、または Location-ヘッダー アンケート URL (202)

関連ブログ記事
この機能に関するブログ記事はまだありません。近日公開予定です。
その間、PDF4me ブログを閲覧して、あらゆるプラットフォームのチュートリアルやワークフローをご覧ください。
ブログをご覧ください →

認証 API リクエスト​

毎 PDF4me REST 電話にはあなたの API キー Authorization ヘッダーを基本認証として設定します。開発者ダッシュボードからキーを取得またはローテーションしてください。

終点​

役職/api/v2/GenerateDocumentSingle

見逃してはならない重要な事実​

どちらか ドキュメントデータテキスト または ドキュメントデータファイル
コンテンツを持つデータソースは、両方ではなく、正確に1つだけ設定する必要があります。 ドキュメントデータテキスト インライン用 JSON / XML / CSV。 使用 ドキュメントデータファイル のために Base64-エンコードされたデータファイルまたは公開 URL。
許可される出力タイプはテンプレートファイルタイプによって異なります
Docx、MailMerge、GoogleDocs に対応 PDF または Docx. HTML は受け入れます HTML PDFのみ対応 PDF のみ。正確なケースサイズが重要です。
非同期処理は202 + Locationヘッダーを返します
と IsAsync: true の API 202とLocationヘッダーで応答する場合があります。 GET それ URL (同じ認証)レンダリングされたファイルで200まで(標準) pdf4meAsyncRequest パターン)。

HTTP 設定​

方法: 役職
URL: https://api.pdf4me.com/api/v2/GenerateDocumentSingle
コンテンツタイプ: アプリケーション/json
承認: 基本 <あなたの PDF4me API キー>

送信 IsAsync: true 体内で。 200 レンダリングされたファイルのバイト列を返します。 202 を返します 位置 アンケート付きのヘッダー URL; GET それ URL 200 まで同じ Authorization ヘッダーを使用します。

変異マトリックス(ポストマン関連)​

テンプレートバリアント(T1 / T2 / T3)を1つ、データバリアント(D1 / D2 / D3)を1つ選択してください。6つの組み合わせで、すべての呼び出しに対応できます。

テンプレート (templateFileData)​

コードソースポストマンの価値 テンプレートファイルデータまた、必須です。
T1Base64Base64 template file (strip data:...;base64, prefix if present)templateFileName
T2URLFull HTTPS URL string (not downloaded by the API request body)templateFileName
T3HTML codeBase64-encoded UTF-8 HTML: Buffer.from(html, "utf8").toString("base64")templateFileName, templateFileType: HTML

文書データ(2つのうちの1つ) API 分野)​

コードソースAPIフィールド郵便配達員の価値
D1TextdocumentDataTextRaw JSON / XML / CSV string
D2Base64documentDataFileBase64 of the data file (strip data-URL prefix if present)
D3URLdocumentDataFileFull HTTPS URL to .json / .xml / .csv

ルール: ちょうど1つ ドキュメントデータテキスト または ドキュメントデータファイル 設定する必要があります。使用されていないフィールドは本文から除外してください。

一般的な組み合わせ​

#テンプレートデータ典型的な使用例
1T1 Docx base64D1 JSON textWord mail-merge to PDF
2T2 Docx URLD3 JSON URLHosted template + hosted data
3T3 HTMLD1 JSON textHTML mustache rendered to HTML / PDF
4T1 PDF formD2 JSON base64PDF template + encoded data file
5T2 MailMerge URLD1 XML textWord merge fields + inline XML

templateFileType → 許可された出力タイプ​

テンプレートファイルタイプ許可された 出力タイプ注記
DocxPDF, DocxPDF4me Word template
MailMergePDF, DocxMail merge Word
GoogleDocsPDF, DocxGoogle Docs export style
HTMLHTML onlyMustache in HTML
PDFPDF onlyPDF form / template

API ボディフィールド​

常に送信​

パラメータ必須その機能例
jobIdExtOptionalYour own reference for this call. It is stored with the API call log so you can correlate calls with your jobs. Type: string.
integrationsOptionalIntegration identifiers, forwarded unchanged with the job's notification settings. Type: array.
isAsyncOptionalSet to `true` to process the action asynchronously and get a job to poll at `/api/v2/GetActionStatus`. Only honoured by actions that support asynchronous processing. Type: boolean.true
templateFileTypeOptionalType of the template file, e.g. `Docx`, `Html` or `Pdf`. Not used by GenerateDocumentSingleV2.Docx, HTML, PDF, MailMerge, GoogleDocs
templateFileDataOptionalRequired. The template file. Accepts the base64-encoded file content, a `pdf4meblobid://<id>` reference, or an `https` URL. Not used by GenerateDocumentSingleV2, which loads the stored template named by `templateFileName`. Type: string.Base64 template, or template URL string
documentDataTypeOptionalFormat of the data, `Json`, `XML` or `Csv`.Json, XML, or Csv (exact casing)
templateFileNameOptionalRequired. File name of the template, including its extension. For GenerateDocumentSingleV2 it is the name of a template uploaded in the PDF4me Dashboard (https://dev.pdf4me.com/dashboard/#/document-template/), which is loaded instead of `templateFileData`. Type: string.With extension, e.g. template.docx, template.html, template.pdf
documentDataTextOptionalThe data as text. Used when `documentDataFile` is empty. Type: string.Valid JSON when documentDataType is Json; XML must look like XML; CSV non-empty
documentDataFileOptionalThe data as a file. Accepts the base64-encoded file content, a `pdf4meblobid://<id>` reference, or an `https` URL. Takes precedence over `documentDataText`. Type: string.Base64 data file or URL to data file
outputTypeOptionalFormat of the generated document, e.g. `pdf` or `docx`. Not used by GenerateDocumentSingleV2.PDF, Docx, or HTML (see allowed-output table above)
metaDataJsonOptionalOptional document metadata as a JSON string. Type: string.
keepPdfEditableOptionalKeep form fields editable when the output is a PDF. Type: boolean.false

サンプルペイロード​

1. Wordテンプレート(base64)+ JSON テキスト → PDF​

{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataText": "{\"name\": \"John Doe\", \"email\": \"[email protected]\", \"items\": [{\"product\": \"Widget\", \"price\": 29.99}]}",
"outputType": "PDF",
"KeepPdfEditable": false,
"IsAsync": true
}

2. Wordテンプレート(URL)+ JSON データ (URL) → PDF​

{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "https://example.com/template.docx",
"documentDataType": "Json",
"documentDataFile": "https://example.com/data.json",
"outputType": "PDF",
"KeepPdfEditable": false,
"IsAsync": true
}

3. Wordテンプレート(base64)+ JSON データ(base64)→ワード出力​

documentDataFile の base64 を保持します JSON ファイルバイト(解析されたオブジェクトではない)。

{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataFile": "eyJuYW1lIjogIkpvaG4gRG9lIn0=",
"outputType": "Docx",
"IsAsync": true
}

4. HTML テンプレート (base64 の HTML ファイル) + JSON テキスト → HTML​

生の HTML Postmanでは、同じペイロードを送信します。 n8n ノードは: base64エンコードされます HTML で templateFileData。

{
"templateFileType": "HTML",
"templateFileName": "template.html",
"templateFileData": "PCFET0NUWVBFIGh0bWw+...",
"documentDataType": "Json",
"documentDataText": "{\"title\": \"Invoice\", \"heading\": \"Hello\", \"content\": \"World\"}",
"outputType": "HTML",
"IsAsync": true
}

5. メールマージ(URL)+ XML テキスト → PDF​

{
"templateFileType": "MailMerge",
"templateFileName": "template.docx",
"templateFileData": "https://example.com/template.docx",
"documentDataType": "XML",
"documentDataText": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><name>John Doe</name><email>[email protected]</email></root>",
"outputType": "PDF",
"IsAsync": true
}

6. PDF フォームテンプレート(base64)+ CSV テキスト → PDF (編集可能)​

{
"templateFileType": "PDF",
"templateFileName": "template.pdf",
"templateFileData": "JVBERi0xLjQKJcfsj6IK...",
"documentDataType": "Csv",
"documentDataText": "name,email\nJohn Doe,[email protected]",
"outputType": "PDF",
"KeepPdfEditable": true,
"IsAsync": true
}

7. Googleドキュメントスタイル(base64)+ JSON URL → Docx​

{
"templateFileType": "GoogleDocs",
"templateFileName": "template.docx",
"templateFileData": "UEsDBBQAAAAI...",
"documentDataType": "Json",
"documentDataFile": "https://example.com/data.json",
"outputType": "Docx",
"IsAsync": true
}

郵便配達員の集荷に関するヒント​

Body
Use raw JSON. The API does not accept form-data for this endpoint.
Base64 of data
For D2, base64-encode the whole .json / .xml / .csv file and put it in documentDataFile. Set documentDataType accordingly.
HTML template
For T3 in Postman: Buffer.from(html, "utf8").toString("base64"). Send the base64 in templateFileData with templateFileType: HTML.
Filename match
Match the extension in templateFileName to templateFileType: .docx for Word / MailMerge / GoogleDocs, .html for HTML, .pdf for PDF.
Save response
Save the response body as .pdf, .docx, or .html depending on outputType.

curlの例​

curl -X POST https://api.pdf4me.com/api/v2/GenerateDocumentSingle \
-H "Content-Type: application/json" \
-H "Authorization: Basic YOUR_API_KEY" \
-d '{
"templateFileType": "Docx",
"templateFileName": "template.docx",
"templateFileData": "https://example.com/template.docx",
"documentDataType": "Json",
"documentDataFile": "https://example.com/data.json",
"outputType": "PDF",
"KeepPdfEditable": false,
"IsAsync": true
}' \
--output generated.pdf

クイックリファレンス:バリアントごとの必須項目と任意項目​

分野T1+D1T2+D3T1+D2T3+D1PDFファイルはすべて出力されます
templateFileTypeReqReqReqReqReq
templateFileNameReqReqReqReqReq
templateFileDataReq (b64)Req (URL)Req (b64)Req (b64 HTML)Req
documentDataTypeReqReqReqReqReq
outputTypeReqReqReqReqReq
documentDataTextReqOmitOmitReqOmit
documentDataFileOmitReq (URL)Req (b64)OmitOmit
IsAsyncReqReqReqReqReq
KeepPdfEditableOptOptOptN/A*Opt if PDF

*KeepPdfEditable 適用条件 出力タイプ は PDF; その API そうでなければ、強制的に誤りを生じさせる。

コードサンプル​

よくある質問​

Can I send both documentDataText and documentDataFile in one request?+
No. Exactly one data source must be set. Omit the unused field. Sending both with content is rejected by the validation layer.
Which output types are allowed for each templateFileType?+
Docx, MailMerge, and GoogleDocs accept PDF or Docx. HTML accepts HTML only. PDF accepts PDF only. The casing of outputType matters.
Does KeepPdfEditable apply to every request?+
No. It only applies when outputType is PDF. For HTML or Docx output the API forces false and ignores the flag.
How do I send raw HTML in Postman?+
Base64-encode the UTF-8 HTML string (Buffer.from(html, "utf8").toString("base64") or the equivalent in your language). Put the result in templateFileData with templateFileType: HTML.
How do I encode the data file for D2?+
Base64-encode the entire .json, .xml, or .csv file bytes, not the parsed object. Put the base64 string in documentDataFile and set documentDataType to match.
How does the async flow work?+
Send IsAsync true. If the API returns 200, the rendered file is in the body. If 202, read the Location header for a poll URL. GET that URL with the same Authorization. Poll until 200.
My template Base64 has a data: prefix. Do I strip it?+
Yes. The API expects raw Base64 in templateFileData. Strip any data:...;base64, prefix before posting. Same applies to documentDataFile.
What extension should the response file have?+
Match outputType: .pdf for PDF, .docx for Docx, .html for HTML.

関連アクション​

他のプラットフォームでも同じタスクを実行​

ヘルプが必要な場合​