Skip to main content

Generate Document action in Zapier: mail merge Word templates into finished PDFs with PDF4me

15 min read
PDF4me Team

Generate Document is a PDF4me action for Zapier that performs a mail merge: it takes a Word, HTML or PDF template plus a JSON or XML data file and returns the filled document. A Zap can watch a folder, merge each record, and save every result without anyone opening Word.

Every mail merge tutorial you will find assumes a person is sitting in Word, clicking through a wizard. That works once. It does not work when a hundred invoices need generating on a schedule, or when the data arrives from a system rather than a spreadsheet on someone's desktop. This post covers the template syntax and the Zap that runs the merge unattended.

The flow at a glance
1. New File in Folder
Dropbox trigger watching the folder your data lands in.
2. Find File
Dropbox fetches the Word template from its own folder.
3. Generate Document
PDF4me merges the data into the template.
4. Create Loop From Line Items
Only needed when the merge returns many documents.
5. Upload File
Dropbox saves each finished document.
The short version

Write merge fields into a Word document using the double angle bracket syntax. Keep that template in one Dropbox folder and let data land in another. A Zap picks up the data, hands both files to PDF4me's Generate Document action, and saves the merged result. Choose the Single action for one document per run, or the Multiple action when one data array should produce many.

Why-Based Q&A​

Why use a Word template rather than build the document in code? Because the people who own the wording are rarely the people who own the code. A Word template can be edited by whoever writes the invoice copy, and the next run picks it up with no deployment and no developer in the loop.

Why JSON or XML instead of a spreadsheet? Those are the shapes a system emits. Mail merge in Word reads a sheet because a human exported one. When the trigger is an order being placed or a form being submitted, the data is already structured, and the merge should accept it in that form.

Why are there two Generate Document actions? Generate Document Single merges one record and returns one file. Generate Documents Multiple takes an array and returns one file per element. Picking the wrong one is the usual reason a Zap produces a single document when a batch was expected.

Why keep the template in its own folder? The trigger watches the data folder. If the template sat alongside the data, uploading a revised template would fire the Zap and attempt a merge against a template as though it were a record.


What You'll Get​

Input: a Word template holding merge fields, plus a JSON or XML record. Output: the merged document, saved back to cloud storage, ready to send or archive.


What You Need​

  • Zapier. Open the PDF4me Zapier app. A multi step Zap needs a paid Zapier plan.
  • PDF4me API key. Get your API key. Connect it the first time you add a PDF4me action.
  • Cloud storage with one folder for templates and a separate folder for incoming data.
  • A Word template with merge fields written in the PDF4me syntax below.

What is a mail merge, in one paragraph?​

A mail merge reads values from a data source and drops each one into the matching placeholder in a template. You keep two things: a template holding the merge fields, and a data source supplying the values. The merge engine combines them and returns a finished document, once per record.

PDF4me accepts Word, HTML and PDF templates. Word is the richest of the three, because the syntax supports conditions, tables, repeating sections, images and inline HTML rather than simple find and replace.

How do you design a Word template?​

Merge fields use double angle brackets around the field name:

<<[FieldName]>>

Drop that into a Word document wherever the value belongs. The name inside the brackets matches a key in your JSON or XML record.

Word template syntax reference​

You wantDocumentation
The full syntax, start to finishOverview
Conditional statementsText controls
Tables that grow with the dataTables
Repeating paragraphs and sectionsRepeat paragraphs
Inserting imagesInsert images
Inserting raw HTMLInsert HTML
Number and date formattingFormatting
Variables and listsVariables
A sample Word mail merge template for a PDF invoice, showing merge fields in double angle brackets inside a table with conditional rows

A sample invoice template using a table and conditions. The table row repeats once per line item in the data.


How do you build the Generate Document Zap?​

The Zap has four moving parts: something to start it, the template, the merge, and somewhere to put the result.

  1. Trigger. Pick the trigger matching where your data arrives. With Dropbox, that is New File in Folder pointed at your data folder.
  2. Fetch the template. The trigger only carries the file that just arrived, so read the template separately. With Dropbox that is Find File, pointed at the template folder with the template's exact file name.
  3. Merge. Add the PDF4me Generate Document action and map both files into it.
  4. Save. Add Upload File to write the result back. If the merge returned several documents, put this inside a Create Loop From Line Items step from Looping by Zapier so it runs once per document.

Generate Document parameters​

ParameterRequiredWhat it does
Template FileRequiredThe template itself, mapped from the step that fetched it.
Template File TypeRequiredWhich kind of template you supplied: Word, HTML or PDF.
Input Data Format TypeRequiredWhether the data arrives as Text or as a File.
Data Text or Data FileRequiredThe record. Which one you fill depends on the line above.
Input Data TypeRequiredThe data's own format: JSON or XML.
Template File NameOptionalNames the template for the action, extension included.
Output Document TypeOptionalThe format of the generated document.
Keep Pdf EditableOptionalLeaves form fields editable in the output.
Meta DataOptionalExtra values passed through to the merge.

Tip. Template File Type and Input Data Type are the pair people most often mismatch. If the output comes back with the placeholders still visible, check those two before anything else: the merge ran, it just had nothing it recognised to merge.

Single vs Multiple, and when the loop is needed​

Single vs MultipleGenerate Document SingleGenerate Documents Multiple
Data shapeOne recordAn array, one object per document
ReturnsOne documentOne document per array element
Needs a loop after itNoYes, to save each result
Typical useOne invoice for one orderA batch of statements from one export
The generated PDF invoice produced by the PDF4me mail merge, with the template merge fields replaced by real values

The merged output. Every placeholder from the template has been replaced, and the table has expanded to one row per line item.


Run the Zap and verify​

  1. Publish the Zap.
  2. Drop a sample record into the data folder and wait for the trigger to poll.
  3. Open Zap runs and confirm the Generate Document step returned a file rather than an error.
  4. Open the output and check two things: no placeholders left visible, and the repeating table has the right number of rows.

What did you actually build? A document factory whose wording is owned by whoever edits the template, not by whoever maintains the Zap. Change the template and the next run uses it. The same pattern runs on Make, n8n and Power Automate with the same action.


Common Variations You Can Add Without Rebuilding​

Email the document
Add a Gmail or Outlook step and attach the merged file, so the recipient gets it without anyone opening storage.
Sign it before sending
Insert the PDF4me sign action after the merge so the document goes out already stamped.
Start from a form instead
Swap the Dropbox trigger for a form or webhook trigger and set Input Data Format Type to Text, pasting the payload straight in.
Convert the result
Follow the merge with Convert HTML to PDF or a format conversion when the template type and the output you want differ.

Common questions​

What is a mail merge?​

Reading values from a data source and inserting each one into the matching placeholder in a template, producing one finished document per record. Word popularised the term with its wizard, but the operation itself has nothing to do with Word: any engine that understands a template and a data format can do it, which is what the Generate Document action is.

How do I mail merge in Word?​

If you mean the desktop wizard, you point Word at a spreadsheet and step through its dialogs. If you mean merging a Word template without that wizard, you write the fields using the double angle bracket syntax above, then hand the template and a JSON or XML record to Generate Document. The template is still a Word file; nothing opens Word to produce the output.

Can I mail merge without Word?​

Yes. The merge runs through the PDF4me API, so no copy of Word is involved at any point. You need Word, or any editor that writes .docx, only to author the template in the first place, and PDF4me also accepts HTML and PDF templates if you would rather not use Word at all.

How do I generate many documents from one template?​

Use Generate Documents Multiple and give it an array, one object per document. It returns a document per element. Then put the upload step inside a Create Loop From Line Items action so each result is saved individually, rather than only the first.


Troubleshooting​

The output still shows the merge fields

The data never matched the template. Check that Input Data Type matches the record's real format, that the record is valid, and that the key names match what is inside the angle brackets, including capitalisation.

Only one document comes out of a batch

Either the Single action was used where Multiple was needed, or the upload step sits outside the loop. Both produce exactly one saved file regardless of how many records went in.

The repeating table has one row

The repeating region was not marked up in the template. A table that grows needs the repeat syntax around the row, not just merge fields inside it. See the repeating paragraphs documentation.

The Zap fires when you edit the template

The template lives inside the watched folder. Move it to its own folder and point the fetch step there.


Next Steps​

The same four step pattern (watch, fetch the template, merge, save) handles any "data in, branded document out" automation.