PDF4me Word Template
What this guide covers
This guide walks you through generating a single invoice PDF in n8n using the bundled template.docx and data.json sample pack. The Word template uses PDF4me <<[fieldName]>> merge tags (LINQ Reporting Engine syntax). You load the .docx as binary data, paste or load matching JSON/XML/CSV, and receive one finished PDF per run.
Before You Start
template.docx is an invoice layout. Dynamic values use <<[InvNr]>>, <<[companyName1]>>, <<[productName]>>, and similar tags. Field names are case-sensitive and must match your data keys exactly.data.json (recommended), test.xml, or test.csv. All three carry the same invoice values. Pick the Document Data Type in the node to match the file format you supply.Sample File Pack
Download all four files below. They are designed to work together: one template plus three equivalent data formats.
<<[field]>> tagsWhat's Inside the Sample Files
Template layout (template.docx)
The sample template is a single-page invoice with fixed labels and dynamic merge fields:
| Document section | Static label (fixed in template) | Merge tag (filled from data) |
|---|---|---|
| Header | INVOICE | (static) |
| Invoice meta | Invoice # | <<[InvNr]>> |
| Invoice meta | Invoice Amount | <<[invAmt]>> |
| Invoice meta | Invoice Date | <<[invDate]>> |
| Invoice meta | PO # | <<[invPO]>> |
| Invoice meta | Billing Period | <<[from]>> to <<[to]>> |
| Billed To | BILLED TO | <<[companyName1]>>, <<[companyName2]>>, <<[addressline1]>>, <<[addressline2]>>, <<[country]>> |
| Line item row | Description / Price / VAT % / AMOUNT (USD) | <<[productName]>>, <<[price]>>, <<[vat]>>, <<[amount]>> |
PDF4me Word templates use <<[fieldName]>> (double angle brackets with square brackets). This is different from HTML mustache syntax ({{fieldName}}). See the Word Template Syntax guide for loops, conditions, and format strings.
Field mapping across all data files
Every dynamic value in the template maps to a key in data.json, an XML element in test.xml, or a CSV column in test.csv:
| Template tag | JSON key (data.json) | XML element (test.xml) | Sample value |
|---|---|---|---|
<<[companyName1]>> | companyName1 | CompanyName1 | Muster AG |
<<[companyName2]>> | companyName2 | CompanyName2 | Hans Muster |
<<[addressline1]>> | addressline1 | AddressLine1 | example street |
<<[addressline2]>> | addressline2 | AddressLine2 | 8000 Zürich |
<<[country]>> | country | Country | Switzerland |
<<[productName]>> | productName | ProductName | PDF4me |
<<[price]>> | price | Price | 1000 |
<<[vat]>> | vat | VAT | 8.00 |
<<[amount]>> | amount | Amount | 1000 |
<<[InvNr]>> | InvNr | InvoiceNumber | 202311InV |
<<[invAmt]>> | invAmt | InvoiceAmount | 1000 |
<<[invDate]>> | invDate | InvoiceDate | 2023-11-24 |
<<[invPO]>> | invPO | PurchaseOrder | 1234567 |
<<[from]>> | from | FromDate | 2023-10-24 |
<<[to]>> | to | ToDate | 2023-10-24 |
The Workflow at a Glance
The fastest way to test the sample pack in n8n:
Manual Trigger → Read Binary File (template.docx) → PDF4me Generate Document (Single) → (optional) Write Binary File
| Step | n8n node | Purpose |
|---|---|---|
| 1 | Manual Trigger | Start the workflow on demand |
| 2 | Read Binary File | Loads template.docx into binary property data |
| 3 | PDF4me → Generate Document (Single) | Merges template + data, outputs one PDF |
| 4 | Write Binary File (optional) | Saves generated_document_output.pdf to disk |
/generate-document-single-full-word.png)
Target configuration: Word template from binary + JSON pasted in Document Data Text + PDF output
Step 1: Download and Place the Sample Files
- Download
template.docxanddata.jsonfrom the Sample File Pack above. - Save both files somewhere n8n can read them, for example
C:\pdf4me-samples\on a self-hosted instance, or upload them to Google Drive / Dropbox if you prefer cloud triggers later. - Optionally download
test.xmlortest.csvif you want to test XML or CSV data types instead of JSON.
Step 2: Create the n8n Workflow
- In n8n, create a new workflow.
- Add a Manual Trigger node (or any trigger you prefer for production).
- Add a Read Binary File node after the trigger.
- Add PDF4me → Generate Document (Single) after Read Binary File.
- Connect the nodes in sequence.
Step 3: Load the Word Template (Read Binary File)
Configure the Read Binary File node:
| Field | Value |
|---|---|
| File Path | Full path to your downloaded template.docx |
| Property Name | data (default; this becomes the binary property the PDF4me node reads) |
Execute this node once and confirm the output item shows a binary field named data with filename template.docx.
Step 4: Configure PDF4me Generate Document (Single)
Open the PDF4me node and set these fields. Values below match the sample pack exactly.
Core settings
| Field | Value | Notes |
|---|---|---|
| Credential to connect with | Your PDF4me credential | Get API key |
| Resource | Generate | |
| Generate Operations | Generate Document (Single) | |
| Template File Type | PDF4me Word Template | Matches .docx with <<[field]>> tags |
| Output Type | Use Word if you need an editable merged .docx instead |
Template input (from Read Binary File)
| Field | Value |
|---|---|
| Template File Input Type | Binary Data |
| Template Binary Property | data |
| Template File Name | template.docx |
Document data (paste JSON from data.json)
| Field | Value |
|---|---|
| Document Data Input Type | Text |
| Document Data Type | JSON |
| Document Data Text | Paste the full contents of data.json (see block below) |
{
"companyName1": "Muster AG",
"companyName2": "Hans Muster",
"addressline1": "example street",
"addressline2": "8000 Zürich",
"country": "Switzerland",
"productName": "PDF4me",
"price": 1000,
"vat": 8.0,
"amount": 1000,
"InvNr": "202311InV",
"invAmt": 1000,
"invDate": "2023-11-24",
"invPO": "1234567",
"from": "2023-10-24",
"to": "2023-10-24"
}
Output options
| Field | Value |
|---|---|
| Keep PDF Editable | Off (default) |
| Binary Data Output Name | data (default) |
Step 5: Execute and Verify the PDF
- Click Execute workflow (or run from the PDF4me node).
- Open the PDF4me node output. Under Binary, open the file in property
data(filenamegenerated_document_output.pdf). - Confirm the rendered invoice shows:
- Invoice # →
202311InV - Billed To → Muster AG / Hans Muster / example street / 8000 Zürich / Switzerland
- Line item → PDF4me, price 1000, VAT 8.00, amount 1000
- Billing Period →
2023-10-24to2023-10-24
- Invoice # →
If a field renders blank, compare the tag name in template.docx with the JSON key. They must match exactly (including case: InvNr not invNr).
Step 6: Save the Output (Optional)
Add a Write Binary File node after PDF4me:
| Field | Value |
|---|---|
| File Name | invoice-output.pdf (or use an expression) |
| Data Property Name | data |
| Output Path | Folder where n8n should write the file |
Alternative Data Formats
The same template.docx works with all three data files in the sample pack. Only the Document Data Type and payload change.
Option A: JSON file as binary (data.json)
- Add a second Read Binary File node for
data.json. - Use a Merge node to combine template binary and data binary into one item (or run data load in a separate branch).
- In PDF4me: Document Data Input Type = Binary Data, Document Data Type = JSON, Document Binary Property =
data, Document Data File Name =data.json.
When template and data both use property data on the same item, they overwrite each other. Use separate property names (e.g. template and dataFile) or merge items from two Read Binary File nodes.
Option B: XML (test.xml)
Set Document Data Type to XML and paste the contents of test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Invoice>
<CompanyName1>Muster AG</CompanyName1>
<CompanyName2>Hans Muster</CompanyName2>
<AddressLine1>example street</AddressLine1>
<AddressLine2>8000 Zürich</AddressLine2>
<Country>Switzerland</Country>
<ProductName>PDF4me</ProductName>
<Price>1000</Price>
<VAT>8.00</VAT>
<Amount>1000</Amount>
<InvoiceNumber>202311InV</InvoiceNumber>
<InvoiceAmount>1000</InvoiceAmount>
<InvoiceDate>2023-11-24</InvoiceDate>
<PurchaseOrder>1234567</PurchaseOrder>
<FromDate>2023-10-24</FromDate>
<ToDate>2023-10-24</ToDate>
</Invoice>
Option C: CSV (test.csv)
Set Document Data Type to CSV and paste the CSV body (header row + one data row):
companyName1,companyName2,addressline1,addressline2,country,productName,price,vat,amount,InvNr,invAmt,invDate,invPO,from,to
"Muster AG","Hans Muster","example street","8000 Zürich","Switzerland","PDF4me",1000,8.00,1000,"202311InV",1000,"2023-11-24","1234567","2023-10-24","2023-10-24"
CSV column headers match the JSON keys directly, which map to the <<[fieldName]>> tags in the template.
Production Workflow Patterns
Common ways to supply template and data in productionOnce the sample test works, replace the Manual Trigger and Read Binary File nodes with these patterns.
- Google Drive / Dropbox / OneDrive trigger fires on new file.
- Download node fetches
template.docx(or use a fixed template path). - Build JSON in a Code or Set node from CRM/Sheet fields.
- PDF4me merges and outputs PDF to email or storage.
- Webhook receives order/invoice payload.
- Template loaded once from URL or binary store.
- Map webhook body to Document Data Text with an expression.
- Keys must still match
<<[fieldName]>>tags in the template.
- Host
template.docxanddata.jsonat public HTTPS URLs. - Set Template File Input Type = URL, Template File URL = template link.
- Set Document Data Input Type = URL, Document Data File URL = data link.
- No prior download nodes required.
Frequently Asked Questions
Related Guides
- Generate Document (Single) overview: all parameters, output fields, and template types
- Word Template Syntax:
<<[field]>>tags, loops, conditions, formatting - Generate PDF from Word Template in Make: same sample pattern in Make