Mail merge to PDFs with the right file names
Short version
- Word names merged files by counting:
doc1,doc2. Nothing in it builds a name from your data. - The usual answers are a VBA macro, or hiding the file name in the document as an invisible heading and splitting the PDF by bookmark afterwards.
- The alternative is to name each file as it is made, from a pattern like
Invoice_{{client}}_{{month}}.pdf.
Why this is a separate problem
Getting one PDF per record is one job. Getting Invoice_Rossi_March.pdf instead of doc7.pdf is another, and it is the one that decides whether the folder is usable.
It matters most at the end of the chain. If the next step is attaching each file to an email, the file name is what the sending tool matches against a row, and a folder of numbered files means opening all of them to find out which is which. Fifty is where people stop doing that by hand.
What people do instead
The invisible heading and the bookmark split
Merge the file name into the top of each record as text in 0.1pt white, styled as Heading 1. Export to PDF with «Create bookmarks using headings» ticked, then split the PDF by bookmarks in Acrobat, using the bookmark name as the file name.
It is a genuinely clever trick and it produces the right result. It also wants Acrobat, it puts invisible text in a document you may be sending to a client, and it is four steps that nobody remembers six months later when the same job comes round again.
A VBA macro
A dozen lines loop over the records and save each one with a name built from a merge field. People have been passing the same snippet around for fifteen years, and it works.
Then you meet the machine where it does not: Word on the Mac, Word on the web, or the work laptop where IT blocks macros. That last one is the common case in the threads where this gets asked, and the answer offered is usually a macro-enabled workbook to download from a stranger, which is a hard thing to run against a spreadsheet of client data.
Splitting every N pages
Merge to one PDF, then cut it every two pages. This holds until one record runs onto a third page. From there every split lands in the wrong place, and nothing warns you: you find out when somebody receives the back half of another customer's letter.
Naming the file as it is made
The alternative is to build the name at the moment each PDF is created, from the same row that filled the document. You write a pattern once and every file follows it:
Invoice_{{client}}_{{month}}.pdf
Certificate — {{student}}.pdf
{{reference}}.pdf Two things decide whether this works on a real spreadsheet, and they are worth asking of any tool that offers it.
What happens when two rows produce the same name. Two clients called Rossi, one pattern, and one of them silently overwrites the other inside the folder. A batch of 200 that quietly delivers 198 is worse than one that fails. The right behaviour is to number the second: Invoice_Rossi.pdf and Invoice_Rossi (2).pdf.
What happens to a slash in a company name. Characters like / \ : * ? " < > | are not allowed in file names on Windows or macOS, and
«Rossi S.r.l. / Bianchi» is an ordinary thing for a column to contain. They have to be replaced
before the file is written, not after it fails.
Doing it in the browser
boolkpdf does this part without a macro and without an install. You load the spreadsheet, use the .docx you already have as the template or place values on a PDF, and set the pattern in a field above the list of names, which updates as you type so you can see what the files will be called before you generate them. The download is a ZIP with one correctly named PDF per row.
Duplicates get numbered and forbidden characters are replaced, per the two questions above. The spreadsheet and the finished PDFs stay in your browser: nothing is uploaded, which is the other half of why the macro workbook was a bad answer.
When this is not your problem
If what you need is one document to print, Word's merge is already right and a folder of files is a step backwards. And if you want the files emailed as well as named, this stops at the ZIP — Yet Another Mail Merge on Gmail and Mail Merge Toolkit on Outlook both take a folder of named files and send them, and the naming pattern is what they match against each row.
Try it with your spreadsheet — free for the first 25 rows, no account needed.