Mail merge onto a PDF background

Posted on Fri 16 November 2012 in WebDev & Code

Some days, I love computers.

Days like today, where we want send a mailshot to 900 past customers. I got the address list from our MS Access database. I got a PDF of the artwork. What I wanted to do was create a mail merge using the PDF as a background.

Libreoffice/Openoffice didn't seem to have a neat way of adding a background so I googled the problem and instantly found the solution here.

When I next read this, with my luck the page will be gone, so here's the important bit just in case.

So, solution; pdftk + background
I had been reading the pdftk manual like the bishop reads the bible. I don't know what that means, but I think it is bad. Anyway I only saw what I wanted to see, and that was not background.

The merging I've been looking for was right there. And so the years I spent on this problem were finished! Here's the procedure:

Use OpenOffice to mail merge all the names just like blank pages.
Export as PDF.
So you'll get this big, blank document:

Open a terminal, and add the boat as a background to your 30.000 page PDF.
pdftk names.pdf background boat_background.pdf output out.pdf

And there you go. The sweet deal about this, is that the background is only saved once, and referenced on all the other pages. Nice, just like I wanted.

I'm sure there are other ways to solve this, but this was quick and easy (more so because pdftk is open source and ready to run on Mac OS X, linux and windows).