How to combine multiple .pdf files into a single document

As part of a NASA proposal I am writing, I need to be able to combine multiple .pdf files into a single, larger .pdf file. Sure, you can do this with Acrobat — but you have to pay for it. Today I was delighted to learn about pdftk, the PDF toolkit from AccessPDF. You can download the program here, although I instead got it via fink on my Mac, so your mileage may vary.

At any rate, this gem of a program runs on the command line with simple, easy-to-use syntax. For example, to concatenate f1.pdf and f2.pdf, you type

pdftk f1.pdf f2.pdf cat output combinedfile.pdf

But wait, there’s more! You can pick and choose which pages you want, e.g.

pdftk A=f1.pdf B=f2.pdf cat A1-3 B2-4 A6 output combinedfile.pdf

to get the first three pages from f1.pdf, then pages 2-4 from f2.pdf, then page 6 from f1.pdf… neatly organized in the order you specify! And these are just some of the “simple examples”. There’s more power here than I’ll probably ever need in terms of PDF manipulation. Thank you, Sid Stewart.

Postscript: although this program works like a charm for small files, it dies an ugly death on large ones. The best alternative I was able to find for the Mac is Combine PDFs, which handles large files just fine. However, it is a graphical app. This is handy, since you can drag-and-drop PDF files into it and assemble them manually, but it is also difficult to automate. pdftk is a command-line app, so it’s easy to incorporate it into a Makefile to automatically refresh your output .pdf file if any of the components change; Combine PDFs has to be run manually each time. Still, it was able to give me what I needed for the proposal. Thanks, MonkeyBread Software.