Skip to main content

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

Word template with merge tags
The sample 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.
Matching data file
Use 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.
PDF4me credential in n8n
Create a PDF4me credential in n8n and paste your API key. The same key works across all PDF4me nodes in your instance.

Sample File Pack

Download all four files below. They are designed to work together: one template plus three equivalent data formats.

What'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 sectionStatic label (fixed in template)Merge tag (filled from data)
HeaderINVOICE(static)
Invoice metaInvoice #<<[InvNr]>>
Invoice metaInvoice Amount<<[invAmt]>>
Invoice metaInvoice Date<<[invDate]>>
Invoice metaPO #<<[invPO]>>
Invoice metaBilling Period<<[from]>> to <<[to]>>
Billed ToBILLED TO<<[companyName1]>>, <<[companyName2]>>, <<[addressline1]>>, <<[addressline2]>>, <<[country]>>
Line item rowDescription / Price / VAT % / AMOUNT (USD)<<[productName]>>, <<[price]>>, <<[vat]>>, <<[amount]>>
Merge tag syntax

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 tagJSON key (data.json)XML element (test.xml)Sample value
<<[companyName1]>>companyName1CompanyName1Muster AG
<<[companyName2]>>companyName2CompanyName2Hans Muster
<<[addressline1]>>addressline1AddressLine1example street
<<[addressline2]>>addressline2AddressLine28000 Zürich
<<[country]>>countryCountrySwitzerland
<<[productName]>>productNameProductNamePDF4me
<<[price]>>pricePrice1000
<<[vat]>>vatVAT8.00
<<[amount]>>amountAmount1000
<<[InvNr]>>InvNrInvoiceNumber202311InV
<<[invAmt]>>invAmtInvoiceAmount1000
<<[invDate]>>invDateInvoiceDate2023-11-24
<<[invPO]>>invPOPurchaseOrder1234567
<<[from]>>fromFromDate2023-10-24
<<[to]>>toToDate2023-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
Stepn8n nodePurpose
1Manual TriggerStart the workflow on demand
2Read Binary FileLoads template.docx into binary property data
3PDF4me → Generate Document (Single)Merges template + data, outputs one PDF
4Write Binary File (optional)Saves generated_document_output.pdf to disk
Generate Document (Single) n8n node configured with 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

Target configuration: Word template from binary + JSON pasted in Document Data Text + PDF output


Step 1: Download and Place the Sample Files

  1. Download template.docx and data.json from the Sample File Pack above.
  2. 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.
  3. Optionally download test.xml or test.csv if you want to test XML or CSV data types instead of JSON.

Step 2: Create the n8n Workflow

  1. In n8n, create a new workflow.
  2. Add a Manual Trigger node (or any trigger you prefer for production).
  3. Add a Read Binary File node after the trigger.
  4. Add PDF4me → Generate Document (Single) after Read Binary File.
  5. Connect the nodes in sequence.

Step 3: Load the Word Template (Read Binary File)

Configure the Read Binary File node:

FieldValue
File PathFull path to your downloaded template.docx
Property Namedata (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

FieldValueNotes
Credential to connect withYour PDF4me credentialGet API key
ResourceGenerate
Generate OperationsGenerate Document (Single)
Template File TypePDF4me Word TemplateMatches .docx with <<[field]>> tags
Output TypePDFUse Word if you need an editable merged .docx instead

Template input (from Read Binary File)

FieldValue
Template File Input TypeBinary Data
Template Binary Propertydata
Template File Nametemplate.docx

Document data (paste JSON from data.json)

FieldValue
Document Data Input TypeText
Document Data TypeJSON
Document Data TextPaste 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

FieldValue
Keep PDF EditableOff (default)
Binary Data Output Namedata (default)

Step 5: Execute and Verify the PDF

  1. Click Execute workflow (or run from the PDF4me node).
  2. Open the PDF4me node output. Under Binary, open the file in property data (filename generated_document_output.pdf).
  3. 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 Period2023-10-24 to 2023-10-24

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:

FieldValue
File Nameinvoice-output.pdf (or use an expression)
Data Property Namedata
Output PathFolder 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)

  1. Add a second Read Binary File node for data.json.
  2. Use a Merge node to combine template binary and data binary into one item (or run data load in a separate branch).
  3. In PDF4me: Document Data Input Type = Binary Data, Document Data Type = JSON, Document Binary Property = data, Document Data File Name = data.json.
Binary property name collision

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.
Cloud storage trigger
  1. Google Drive / Dropbox / OneDrive trigger fires on new file.
  2. Download node fetches template.docx (or use a fixed template path).
  3. Build JSON in a Code or Set node from CRM/Sheet fields.
  4. PDF4me merges and outputs PDF to email or storage.
Webhook with dynamic JSON
  1. Webhook receives order/invoice payload.
  2. Template loaded once from URL or binary store.
  3. Map webhook body to Document Data Text with an expression.
  4. Keys must still match <<[fieldName]>> tags in the template.
Public URLs for template and data
  1. Host template.docx and data.json at public HTTPS URLs.
  2. Set Template File Input Type = URL, Template File URL = template link.
  3. Set Document Data Input Type = URL, Document Data File URL = data link.
  4. No prior download nodes required.

Frequently Asked Questions

What placeholder syntax does PDF4me Word Template use?+
Use <<[fieldName]>> inside your .docx file. This is the PDF4me LINQ Reporting Engine syntax, not HTML mustache {{fieldName}}. For loops use <<foreach [item in items]>> ... <</foreach>>, for conditions use <<if [condition]>> ... <</if>>. See the Word Template Syntax guide for the full reference.
Why is a field blank in the generated PDF?+
The data key must match the template tag exactly, including case. InvNr in the template requires "InvNr" in JSON, not "invoiceNumber" or "invnr". Open template.docx and compare each <<[tag]>> with your data file. Empty values also render as blank without an error.
Can I use data.json as a file instead of pasting JSON?+
Yes. Load data.json with Read Binary File, set Document Data Input Type to Binary Data, Document Data Type to JSON, and point Document Binary Property to the binary field. If the template also uses binary property data, rename one property (e.g. template vs dataFile) or merge items from separate nodes.
JSON vs XML vs CSV: which should I use?+
JSON is the simplest for n8n because keys map directly to <<[fieldName]>> tags (as in data.json). XML (test.xml) uses PascalCase element names that PDF4me binds to the same template fields. CSV (test.csv) uses column headers matching the JSON keys, which is useful when data comes from spreadsheets or exports.
PDF or Word output?+
Set Output Type to PDF for sharing, emailing, or archiving. Set Output Type to Word when the recipient needs to edit the merged document after generation. The sample invoice works with both.