Guide
Mail merge to PDF with Google Docs and Apps Script
Updated
For a job that repeats, Google Docs with Apps Script is the better route.
Want the script written for you?
2 minutes
If you ask, up to three software firms will call or email you.
Want somebody to build the pipeline?
Tell us the volume and what has to come out the other end. Up to three document and data extraction software suppliers will contact you directly.
- Free to use
- No account needed
- Steps from each maker's own guides
- Suppliers only if you ask
- Your details go to up to three document software suppliers, and no one else.
- No spam, ever. Privacy notice
Most people arrive here after failing at Word. For a recurring job this route is the better answer, not the consolation prize.
Merge to PDF Tool Index What each route can and cannot do
Question 1
What do you need out of it?
This is the decision that separates a five minute job from a scripting project, and it is worth being precise about before you start.
Email me this result
We will send you these figures and a link back to them. One email, nothing else unless you tick the box.
The shape
A template document containing placeholder text. A spreadsheet holding one row per record. A script that, for each row, copies the template and replaces the placeholders with the row's values. It exports the copy as a PDF, saves it under a name built from the row, and optionally emails it.
Google's Apps Script documentation for Docs covers the document manipulation. The important structural point is that exporting as PDF and writing a named file are both ordinary operations here, which is exactly what Word is missing.
Test on three rows
A script that produces the wrong output produces a great deal of it very quickly, and cleaning up three thousand wrong files is worse than producing them.
Point it at a three-row copy of the sheet first, open all three, then run the real thing.
Batches and time limits
Long runs hit execution time limits. Write the script to process a batch and record where it stopped, so a partial run resumes rather than restarts.
That also makes a failure recoverable at three in the morning, which matters once the job is on a schedule.
Delete the intermediate copies
The natural implementation copies the template, edits the copy, exports it and moves on, leaving one document per record behind alongside every PDF.
Delete them in the loop. A tidy-up job afterwards is a job somebody has to remember, and nobody does.
Why it wins for recurring work
It runs unattended on a trigger. No desktop merge does, and that is the difference between a task somebody performs monthly and a process that happens.
It also removes the operating system question entirely, which is the practical reason it is often the right answer for anybody on a Mac.