Guide

Mail merge to PDF with Google Docs and Apps Script

Updated

Most people arrive at this route after failing at the Word one, which is a shame, because for a recurring job it is the better answer rather than the consolation prize.

Talk to a specialist What has to come out, and what you are working with. Two answers and the method is decided.

The shape

A template document containing placeholder text. A spreadsheet holding one row per record. A script that, for each row, copies the template, replaces the placeholders with values from the row, 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.

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.

Tick the box above to send your enquiry.

  • Free, no obligation
  • We never ask you to upload a document here
  • No marketing lists, ever

Sources

  1. Microsoft, use mail merge for bulk email, letters, labels and envelopes
  2. Microsoft, mail merge using an Excel spreadsheet
  3. Google, Apps Script guide to Google Docs
  4. Section508.gov, creating accessible PDFs
  5. Section508.gov, laws and policies

Find the route before you open Word

What has to come out, and what you are working with. Two answers and the method is decided.

Talk to a specialist