跳到主要内容

Generate Document (Single) in n8n

Generate Document (Single) is an n8n node by PDF4me that merges a Word, HTML, PDF form, Mail Merge, or Google Docs template with JSON, XML, or CSV data to produce one finished document per workflow run. Use it for signed contracts, personalized letters, or on-demand reports without custom code.

What this node does

PDF4me: Generate Document (Single) merges one template with one set of data and returns one finished document per n8n run. Supports five template types (PDF4me Word Template, HTML, Pdf Form, Mail Merge, Google Docs) and three data formats (JSON, XML, CSV). Template enters via Binary Data, Base64, pasted HTML Code (HTML only), or a URL; data enters via Text, Binary Data, Base64, or URL. Ideal for single contracts, personalised letters, on-demand reports, or any one-off document. For list-driven batches use Generate Documents (Multiple).

相关博客文章
目前尚无关于此功能的博客文章——敬请期待。
在此期间,您可以浏览 PDF4me 博客,查看适用于各平台的教程和工作流程。
访问博客

Choose your template type

Pick the guide that matches your Template File Type in the n8n node. Each page lists the exact sample template, data files (JSON, XML, CSV), recommended field values, and a quick test workflow.

Authenticating Your API Request

Every PDF4me node in n8n requires a valid Credential to connect with. Create or select one that holds your PDF4me API key so the workflow can authenticate template-merge requests securely.

Important Facts You Should Not Miss

One document per run, one output item
Each execution returns exactly one n8n item carrying one binary file under Binary Data Output Name (default data). To produce many files from a list of records in one execution, use Generate Documents (Multiple) instead, or wrap this node in a loop.
HTML Code is HTML-only, even though the dropdown shows it everywhere
Template File Input Type lists HTML Code for every Template File Type, but it is only valid when Template File Type is HTML. For Word, Pdf Form, Mail Merge, or Google Docs, use Binary Data, Base64 String, or URL.
Placeholder names must match your data keys exactly
Mustache-style placeholders ({{name}}) or Word merge fields must align with keys in your JSON/XML or column headers in your CSV. Mismatches render as empty values silently.
Generate Document (Single) n8n node configured with Credential Pdf4me, Resource Generate, Generate Operations Generate Document (Single), Template File Type PDF4me Word Template, Output Type PDF, Template File Input Type Binary Data, Template Binary Property data, Template File Name template.docx, Document Data Input Type Text, Document Data Type JSON, sample Document Data Text JSON payload, Keep PDF Editable toggle, Binary Data Output Name data

Default Word path: Word template (binary) + JSON Text data + PDF output

Generate Document (Single) n8n node configured with Template File Type HTML, Output Type HTML, Template File Input Type HTML Code, Template File Name template.html, HTML Code editor showing pasted DOCTYPE template, Document Data Input Type Text, Document Data Type XML, Document Data Text sample JSON array data, Binary Data Output Name data

HTML path: pasted HTML Code + XML/JSON data + HTML output

What Parameters Does Generate Document (Single) Need?

Required in the n8n UI: Credential to connect with, Template File Type, Template File Input Type, Document Data Input Type, Document Data Type, and Output Type (always shown. choices depend on Template File Type). Conditional required fields (Template Binary Property, Template Base64 Content, HTML Code, Template File URL, Document Data Text, Document Binary Property, etc.) appear only when their parent input type is chosen. Keep PDF Editable, Binary Data Output Name, and Template File Name (for Binary Data input) are optional with sensible defaults.

ParameterRequiredWhat it doesExample
Template File TypeRequiredFormat of the template. Choose PDF4me Word Template (.docx), HTML (file or pasted code), Pdf Form (PDF with form/merge fields), Mail Merge (Word mail-merge), or Google Docs (Google Docs export style).PDF4me Word Template
Output TypeRequiredFormat of the rendered document. Word, Mail Merge, and Google Docs accept PDF or Word (default PDF). HTML accepts HTML only. Pdf Form accepts PDF only.PDF
Template File Input TypeRequiredHow the template is supplied. Binary Data reads from a previous node (default, most common). Base64 String accepts an encoded template. HTML Code accepts pasted raw HTML (HTML template type only). URL downloads the template from a public link.Binary Data
Template Binary PropertyConditionalName of the binary property on the incoming n8n item that holds the template file. Required when Template File Input Type is Binary Data. Defaults to data.data
Template Base64 ContentConditionalBase64-encoded template content. Required when Template File Input Type is Base64 String.UEsDBBQAAAAI...
HTML CodeConditionalRaw HTML body with mustache placeholders like {{title}}, {{heading}}, {{content}}. Required when Template File Input Type is HTML Code (and only valid when Template File Type is HTML). The node wraps the snippet in a basic <html> shell if missing.<h1>{{title}}</h1>
Template File URLConditionalPublicly reachable HTTPS URL to the template file. Required when Template File Input Type is URL.https://example.com/template.docx
Template File NameConditionalFilename of the template. Optional with Binary Data (falls back to the uploaded filename or a default like template.docx, template.html, template.pdf based on template type). Required for Base64 String, HTML Code, and URL.template.docx
Document Data Input TypeRequiredHow the data is supplied. Text is the default (paste JSON, XML, or CSV directly). Binary Data reads a data file from a previous node. Base64 String accepts an encoded data file. URL downloads the data file from a public link.Text
Document Data TypeRequiredFormat of the data payload. JSON for object/array, XML for XML documents, CSV for comma-separated rows. Drives both validation and the placeholder examples shown in the UI.JSON
Document Data TextConditionalRaw JSON, XML, or CSV payload. Required when Document Data Input Type is Text. The node validates JSON parses, XML looks like XML, and CSV is non-empty.{"name":"John Doe","email":"[email protected]"}
Document Binary PropertyConditionalName of the binary property on the incoming n8n item that holds the data file. Required when Document Data Input Type is Binary Data. Defaults to data.data
Document Base64 ContentConditionalBase64-encoded data file. Required when Document Data Input Type is Base64 String.eyJuYW1lIjoiSm9obiJ9
Document Data File URLConditionalPublicly reachable HTTPS URL to the data file. Required when Document Data Input Type is URL.https://example.com/data.json
Document Data File NameConditionalFilename for the data file. Optional with Binary Data (falls back to data.json based on type). Required for Base64 String and URL.data.json
Keep PDF EditableOptionalOnly shown when Output Type is PDF. Keeps AcroForm fields editable in the generated PDF when enabled. Default off (flattened).Off
Binary Data Output NameOptionalName of the binary property the output item exposes. Default is data. The node sets the download filename automatically as generated_document_output.<ext>.data

Template File Type Options

Five template types. The choice drives which Output Type options appear and which Template File Input Types are practical. Open the matching guide above for sample files and field-by-field setup.

Template File Type dropdown in n8n PDF4me Generate Document (Single) node showing five options: PDF4me Word Template highlighted, HTML, Pdf Form, Mail Merge, and Google Docs

Template File Type dropdown in the n8n node

Output Type by Template

Template File TypeOutput Type choicesDefault
PDF4me Word TemplatePDF, WordPDF
Mail MergePDF, WordPDF
Google DocsPDF, WordPDF
HTMLHTML onlyHTML
Pdf FormPDF onlyPDF
Output Type dropdown in n8n PDF4me Generate Document (Single) node showing PDF highlighted and Word as the two options for a Word-family template

Output Type dropdown shown for Word-family templates: PDF (default) or Word

Template File Input Type Options

Pick how the template enters the node. The follow-up fields change with this choice.

Template File Input Type dropdown in n8n PDF4me Generate Document (Single) node showing four options: Binary Data highlighted with description Use template file from previous node, Base64 String with description Provide base64 encoded template file, HTML Code with description Write raw HTML code manually only available for HTML template type, URL with description Provide a URL to the template file

Template File Input Type. Binary Data, Base64 String, HTML Code, or URL

Binary DataDefault: file from previous node
Reads the template directly from a prior node such as Google Drive Download, HTTP Request, or Read Binary File. Set Template Binary Property to the binary field name (default data). Template File Name is optional and falls back to the uploaded filename.
Base64 StringBase64-encoded template
Paste or map a base64 string into Template Base64 Content. Template File Name is required so the extension matches the Template File Type (.docx, .html, .pdf).
HTML CodePaste raw HTML inline (HTML only)
Only valid when Template File Type is HTML. Type full or partial HTML with placeholders like {{title}}, {{content}}. The node wraps it in a basic <html> shell if missing. Template File Name is required (e.g. template.html).
URLDownload from a public link
Provide an HTTPS URL in Template File URL. PDF4me fetches the template directly. The URL must be open (no auth) and Template File Name is required so the extension matches the template type.

Document Data Input Type Options

Pick how the data enters the node.

Document Data Input Type dropdown in n8n PDF4me Generate Document (Single) node showing four options: Text highlighted with description Manually enter JSON or XML data, Binary Data with description Use data file from previous node, Base64 String with description Provide base64 encoded data file, URL with description Provide a URL to the data file

Document Data Input Type. Text, Binary Data, Base64 String, or URL

TextDefault: paste data inline
Type or expression-map the data into Document Data Text. The node validates JSON parses, XML looks like XML, and CSV is non-empty. The UI shows a placeholder example matching your Document Data Type.
Binary DataUse a data file from a previous node
Set Document Binary Property to the binary field name (default data). Watch that template and data binary property names do not collide when both come from the same item; use a Merge node if needed.
Base64 StringBase64-encoded data file
Provide the entire .json, .xml, or .csv file as base64 in Document Base64 Content. Document Data File Name is required so the extension matches the data type.
URLDownload from a public link
Set Document Data File URL to a public HTTPS URL of the JSON, XML, or CSV file. Document Data File Name is required.

Document Data Type Options

Pick the format of the data payload. Drives validation and the inline placeholder example shown for Text input.

Document Data Type dropdown in n8n PDF4me Generate Document (Single) node showing three options: JSON highlighted, XML, and CSV

Document Data Type. JSON, XML, or CSV (Single supports CSV; Multiple does not)

JSONDefault: object or array data
Pass an object whose keys match template placeholders, e.g. {"name":"John","email":"[email protected]","items":[...]}. The node validates that the payload parses with JSON.parse.
XMLXML document
Send an XML document the template engine can bind to, e.g. <?xml version="1.0"?><root><name>John</name></root>. Node checks the payload starts with < and contains >.
CSVComma-separated values
Pass a CSV body with a header row, e.g. name,email\nJohn Doe,[email protected]. The node checks the payload is non-empty after trim. CSV is only available on the Single operation; Multiple does not accept CSV.

Output Fields

A successful run returns one n8n item carrying JSON metadata and the binary file.

FieldTypeWhat it contains
successBooleanTrue when the document was generated successfully. Use to route error-handling branches.
fileNameStringGenerated filename, set automatically to generated_document_output.<ext> based on Output Type (pdf, docx, html).
mimeTypeStringMIME type of the output: application/pdf, application/vnd.openxmlformats-officedocument.wordprocessingml.document, or text/html.
fileSizeNumberSize of the generated file in bytes.
Binary (data)BinaryThe generated document under Binary Data Output Name (default data). Pass into Write Binary File, Email, or any cloud-storage upload.

How Do I Set Up Generate Document (Single) in n8n?

  1. Add PDF4me to your n8n workflow. Set Resource to Generate and Generate Operations to Generate Document (Single).
  2. In Credential to connect with, select your PDF4me credential or click Create New Credential and paste your API key.
  3. Set Template File Type to PDF4me Word Template (default), HTML, Pdf Form, Mail Merge, or Google Docs.
  4. Set Output Type. Word-family templates accept PDF or Word; HTML accepts HTML only; Pdf Form accepts PDF only.
  5. Set Template File Input Type to Binary Data (default), Base64 String, HTML Code (HTML only), or URL and fill the matching template field plus Template File Name if required.
  6. Set Document Data Input Type to Text (default) and paste your payload into Document Data Text. or pick Binary Data, Base64 String, or URL and supply the data file.
  7. Set Document Data Type to JSON (default), XML, or CSV so validation and placeholders match.
  8. If outputting PDF and your template has form fields, toggle Keep PDF Editable as needed.
  9. Leave Binary Data Output Name as data unless a downstream node needs a different property name. Execute the node and route the single output item into Write Binary File, Email, or cloud storage.

Typical Setups

Workflow ExamplesCommon n8n workflow patterns using Generate Document (Single).
Word template + JSON from CRM. signed contract
  1. A CRM webhook fires when a deal is marked Closed-Won.
  2. A Google Drive Download node pulls the standard contract template .docx (Binary Data, property data).
  3. PDF4me Generate Document (Single) runs with Template File Type PDF4me Word Template, Output Type PDF, Document Data Input Type Text. Document Data Text is an expression that maps the deal payload into JSON.
  4. A Sign request node forwards the generated PDF to DocuSign.
HTML email-style document from pasted code
  1. A Schedule Trigger fires every weekday morning.
  2. An HTTP Request node pulls a JSON summary of yesterday's KPIs.
  3. PDF4me Generate Document (Single) runs with Template File Type HTML, Template File Input Type HTML Code. The HTML body is pasted in the node with {{title}}, {{heading}}, {{content}} placeholders. Output Type is HTML.
  4. A Send Email node embeds the generated HTML directly in the email body to the leadership distribution list.
Template + data both as files (merged in n8n)
  1. One node downloads the template; another node downloads the data file. A Merge node combines them so both binaries land on one item.
  2. PDF4me Generate Document (Single) runs with Template File Input Type Binary Data (Template Binary Property set to the template field name) and Document Data Input Type Binary Data (Document Binary Property set to the data field name).
  3. Set Document Data File Name if the data file is not named data.json.
  4. The output PDF is saved to a SharePoint document library with the order ID as filename.
Everything on URLs. hosted template and hosted data
  1. A Webhook Trigger fires from an external billing system.
  2. PDF4me Generate Document (Single) is set with Template File Input Type URL (Template File URL points to the .docx on S3) and Document Data Input Type URL (Document Data File URL points to a generated customer.json).
  3. Match Document Data Type to the data file extension and provide Template File Name and Document Data File Name so PDF4me handles them correctly.
  4. The output PDF is uploaded to Dropbox and emailed via Outlook.
PDF form template with editable fields preserved
  1. A typeform submission triggers the workflow.
  2. PDF4me Generate Document (Single) runs with Template File Type Pdf Form, Output Type PDF, Template File Input Type Binary Data (the PDF form template from Drive). Document data is the form payload as JSON Text.
  3. Keep PDF Editable is turned on so the recipient can correct or extend the auto-filled fields.
  4. The generated PDF is emailed to the applicant for review.

Practical Tips

Placeholders must align with data keys
Mustache {{name}} in the template must match "name" in JSON or the matching XML tag / CSV header. Mismatches render as empty silently.
HTML Code is HTML-only
The dropdown shows HTML Code for every template type but the node rejects it unless Template File Type is HTML.
"No binary data found" errors
Double-check Template Binary Property and Document Binary Property names. The Merge node from a fan-in workflow can rename binary properties.
Invalid JSON stops the run
Document Data Text with Document Data Type JSON is parsed with JSON.parse. Malformed payloads fail early; validate with a Code node if the JSON is dynamic.
Use Multiple for batches
To produce many files from a list of records in one execution, switch to Generate Documents (Multiple). For ad-hoc batches you can also wrap Single in a Loop Over Items node.
Keep PDF Editable only matters for PDF
The toggle appears only when Output Type is PDF. For Word or HTML output it is ignored.

Cheat Sheet

FieldValue
ResourceGenerate
OperationGenerate Document (Single)
Template File TypePDF4me Word Template
Output TypePDF
Template File Input TypeBinary Data
Template Binary Propertydata
Document Data Input TypeText
Document Data TypeJSON
Document Data Text(your inline JSON payload)
Binary Data Output Namedata (or generated-document)
CredentialsPDF4me API credential

Frequently Asked Questions

Which template types does Generate Document (Single) support?+
Five: PDF4me Word Template (.docx with mustache placeholders), HTML (file or pasted code), Pdf Form (PDF with form / merge fields), Mail Merge (Word mail-merge style), and Google Docs (Google Docs export style).
What data formats are accepted?+
JSON, XML, and CSV. Pick Document Data Type to match your data, then choose how to supply it: Text (paste inline), Binary Data (from a previous node), Base64 String, or URL.
When does HTML Code appear in Template File Input Type?+
It appears in the dropdown for every Template File Type, but the node only accepts HTML Code when Template File Type is HTML. For Word, Pdf Form, Mail Merge, or Google Docs, use Binary Data, Base64 String, or URL instead.
What Output Type can I pick for each template?+
PDF4me Word Template, Mail Merge, and Google Docs accept PDF or Word (default PDF). HTML accepts HTML only. Pdf Form accepts PDF only.
Can I generate many documents in one run?+
No, Generate Document (Single) renders exactly one document per execution. To batch a list of records into many files in a single run, use Generate Documents (Multiple). To process records sequentially with the Single node, wrap it in a Loop Over Items.
What happens if my JSON in Document Data Text is invalid?+
The node validates with JSON.parse and fails the run with a format error before calling the API. Validate dynamic JSON with a Code node upstream if you expect untrusted input.
How does the output filename get set?+
Automatically as generated_document_output.<ext> based on Output Type. The download is exposed under Binary Data Output Name (default data) so you can rename it in Write Binary File or any upload node downstream.
Should I turn on Keep PDF Editable for every PDF output?+
No, only when the recipient needs to edit the generated form fields. With Keep PDF Editable off (default), the form is flattened into static text on the final PDF, which is the right choice for delivered records like signed contracts or final invoices.

Same Task on Other Platforms

Get Help