Guide · Google Sheets
How to mail merge from Google Sheets to PDF
Put one row per document in a Google Sheet, write the document once in Google Docs with {{column names}} where the values go, and then let a script or an add-on copy the template for each row, fill it in and save it as a PDF. Google has no built-in button for it, but the free script below takes about ten minutes to set up, and an add-on does it in one click.
Updated 14 November 2026 · 6 min read
What you need
- A Google Sheet with column names in row 1 and one row per document.
- A Google Docs template with fields such as
{{Name}}written exactly like the column names. - A Drive folder for the finished PDFs.
This works for anything you write more than once with different details: course certificates, quotes, letters to members, contracts, offer letters, name badges and simple invoices.
The free way: a short Apps Script
Apps Script is Google's own scripting tool, and it is built into every Google Sheet. You do not need to know how to code to use the script below. You only paste it and add two IDs.
- 1
Put one row per document in your sheet
Column names go in row 1, for example Name, Course and Date. Every row below becomes one PDF. Keep the last column empty, because the script writes the link to each PDF there.
- 2
Write the template in Google Docs
Design the document as you want it to look. Where a value should go, type the column name in double curly brackets, exactly as in row 1: {{Name}}, {{Course}}, {{Date}}.
- 3
Copy two IDs
The template ID is the long code in the Doc's address, between /d/ and /edit. The folder ID is the code at the end of the Drive folder's address. The PDFs will be saved in that folder.
- 4
Paste the script
In your sheet, choose Extensions → Apps Script, delete what is there, paste the script below and put your two IDs in the first two lines.
- 5
Run it
Click Run, allow the access Google asks for, and wait. Each row gets a PDF in the folder and a link in the empty column.
function mergeToPdf() {
const TEMPLATE_ID = 'PASTE_YOUR_TEMPLATE_DOC_ID';
const FOLDER_ID = 'PASTE_YOUR_DRIVE_FOLDER_ID';
const sheet = SpreadsheetApp.getActiveSheet();
const rows = sheet.getDataRange().getDisplayValues();
const headers = rows.shift();
const folder = DriveApp.getFolderById(FOLDER_ID);
const template = DriveApp.getFileById(TEMPLATE_ID);
rows.forEach((row, i) => {
const copy = template.makeCopy('merge-' + (i + 2), folder);
const doc = DocumentApp.openById(copy.getId());
const body = doc.getBody();
headers.forEach((name, col) => {
if (name) body.replaceText('\\{\\{' + name + '\\}\\}', row[col]);
});
doc.saveAndClose();
const pdf = folder.createFile(copy.getAs('application/pdf'));
pdf.setName(row[0] + '.pdf');
copy.setTrashed(true);
sheet.getRange(i + 2, headers.length + 1).setValue(pdf.getUrl());
});
}The PDF gets its name from the first column, so put the person's or customer's name there. The script uses the values as they look in your sheet, so dates and amounts keep the format you see.
Where the script falls short
The script is fine for a one-off batch of a few dozen documents. It gets harder when you do this every week or every month:
- It stops after 6 minutes. Google ends every Apps Script run at that limit, and a long sheet will not finish in one go.
- A second run starts over. Rows that already have a PDF are made again unless you add code to skip them.
- Headers and footers stay empty. The script only fills fields in the body of the document.
- No preview. You see the result only after every PDF is made, so a typo in the template means doing it all again.
- Broad access. The script asks to see and change all files in your Google Drive, because it uses DriveApp.
- Emailing each PDF takes more code.
The one-click way: DocMerge
DocMerge is our Google Sheets add-on, and it does the same job without code. Open it from Extensions, pick your template, look at the first document as a PDF and click Create. It fills fields in the body, tables, headers and footers, writes a link next to each row, keeps going past the 6-minute limit and never makes a row twice. Tick one box and each PDF is emailed from your own Gmail to the person in the row.
It can only open the sheet you are in, the template you pick and the folder you pick. It is free for 25 documents a month, and Pro is €8 a month with no limit.
Questions
Can Google Sheets mail merge to PDF on its own?
No. Google Sheets and Google Docs have no built-in button that makes one PDF per row. Gmail's own mail merge on paid Google Workspace plans sends emails, not separate PDF files. You need either a short Apps Script or an add-on.
Is there a free way to mail merge Google Sheets to PDF?
Yes. The Apps Script on this page is free and works on any Google account. It copies your Google Docs template for each row, fills in the {{fields}}, saves a PDF in a Drive folder and deletes the temporary copy.
Why does my script stop halfway through?
Google stops an Apps Script after 6 minutes on a run. Every PDF takes a few seconds, so a long sheet can hit that limit. If you run it again, this simple script starts from the top and makes the first rows twice. Delete the rows that are done, or use an add-on that continues where it stopped.
Why are {{fields}} in my header or footer not filled in?
The script only replaces text in the body of the document. Fields in headers, footers and footnotes stay as they are unless you add code for them. DocMerge fills fields in the body, tables, headers and footers.
Can I email each PDF to the person in the row?
With the script you would need more code that calls GmailApp for each row. In DocMerge it is one tick box: each PDF is sent from your own Gmail with the subject filled in from your columns, and it is included in the free plan.
What is the easiest way to mail merge Google Sheets to PDF?
An add-on. DocMerge does the same job as the script without code: pick the template, preview the first PDF and click Create. It is free for 25 documents a month and €8 a month with no limit.
Written by AddonNordic ApS, Aalborg, Denmark (CVR 46495985), maker of DocMerge. Google Sheets™, Google Docs™, Google Drive™ and Gmail™ are trademarks of Google LLC; this guide is not made or endorsed by Google.