Combining multiple PDF files into a single file
One of the things I often do at work is use Adobe Acrobat Pro to combine multiple PDF files into a single file. For the most common tasks, I have an AppleScript that combines the files and re-saves them. At home, I don’t have Acrobat Pro, but I still want to occasionally combine PDF files. In the past, I’ve just not done it, but today I finished making a set of reference sheets for the Gods & Monsters role-playing game, and I needed an automated means of combining them.
Preview doesn’t directly combine PDF files, but it turns out that Automator can. Combining PDF files in Automator consists of two to five actions, depending on what you want the results to be.
Automator is in your Applications folder in Mac OS X 10.4 or higher.
- Choose the files. In my case, I already know what files are going to be combined every time, so I used the Finder’s “Get Specified Finder Items” action. I dragged the items into the list. You might instead use the “Ask for Finder Items” if you’ll need to combine different items each time you use the Automator script. If all you want to do is drag and drop the PDF files onto the Automator script, you don’t need this step at all.
- Combine the files. In the list of Applications in Automator, there is one called PDF. That application has “Combine PDF Pages”. This will combine the files from the previous step into a single temporary file.
-
Do something with the new file. The simplest thing to do is to use the Finder’s “Open Finder Items” action, and open with Preview. You can then view the document in Preview and if it meets your needs, save it just as you would any other file in Preview. For full automation, however, you can also automatically rename and copy the file to a pre-specified location. Here’s what I added as steps three through five.:
- Rename PDF document. The temporary combined file has a temporary name. The PDF application has an action called “Rename PDF document” that attempts to give the PDF file a useful name; if it can’t determine the appropriate name, it gives it the name “Untitled”.
- Rename Untitled if necessary. The Finder has an action called “Rename Finder Items”, and you can replace any text in the original name with any other text. I replaced Untitled with Sheets.
- Move the file to the desired location. Using the Finder’s “Move Finder Items” action, I move the file to the Desktop; I could also move it to any location on my computer.
When you’re done making the Automator script, you can save it as an Application; you can then re-use it as you would any other application, by double-clicking on it in Finder. From now on, when I need to combine those thirteen individual PDFs, all I need to do is double-click my Combine Gods & Monsters Sheets application and it will combine them for me, into a file called Sheets.pdf on my desktop.
- May 21, 2007: Automator problems with custom Python
-
I thought I’d implement this simple drag-and-drop PDF combiner at the office today, only to discover that it didn’t work. I made a simpler one: just the two steps “combine PDF” and “open in preview”. I noticed that the files were being created but were empty. In the console app I found the following error:
[toggle code]
-
Traceback (most recent call last):
-
File "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py", line 23, in ?
- from CoreGraphics import *
-
File "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py", line 23, in ?
- ImportError: No module named CoreGraphics
It was interesting to see that at least some Automator functionality is programmed in Python.
My problem was that, at the office, I updated Python from the 2.3 that comes with Mac OS X 10.4 to 2.4, and then I made 2.4 the default (linked /usr/bin/python to /usr/local/bin/python2.4). However, the way Python works is that libraries are installed on a per-version basis. So 2.4 had no idea where to import the core graphics library.
I switched the default Python back to 2.3 and the Automator app began working as expected.
-
Traceback (most recent call last):
- New character sheets, maps, and reference sheets
- The character sheets and reference sheets have been converted to Scribus, and new map grids are availble in Inkscape. All are also made available as PDF files.
More Mac OS X tricks
- Stack windows on top of each other
- If you want to stack multiple windows directly on top of each other, it’s easy to do in any well-behaved application, such as Nisus Writer Pro, Safari, Mail, and even older applications like AppleWorks 6 and Microsoft Word X.
- Leopard setuid and passwd file changes
- Leopard Server introduced two major changes to two lesser-used features: setuid root script wrappers and BSD flat file authentication.
- Media duration in Python on Mac OS X
- It turns out to be very easy to get the duration of MP3 files, MPEGs, and other media files on the OS X command line.
- SilverService and Taskpaper
- SilverService is a great little app if you commonly need to repetitiously modify text. Any application that supports services will support running selected text through command-line scripts via SilverService.
- Using Exposé effectively on Mac OS X
- A few simple tricks with window management in OS X can make working with multiple applications or multiple windows much easier and faster.
- Six more pages with the topic Mac OS X tricks, and other related pages
More PDF
- Calculating true three-fold PDF in Python
- Calculating a true three-fold PDF requires determining exactly where the folds should occur.
- Adding links to PDF in Python
- It is very easy to add links to PDF documents using reportlab or platypus in Python.
- Multiple column PDF generation in Python
- You can use ReportLab’s Platypus to generate multi-column PDFs in Snakelets, Django, or any Python app.
- Embedding Mako into Django
- You got Mako in my Django! You got Django on my Mako! Two great templates that template great together.
- Python PDF generation with Snakelets
- One of the things I need to do to move my current web site over to Django is be able to automatically generate PDF documents. Step is to learn how to generate PDF using Python.
- One more page with the topic PDF, and other related pages

Note: Preview can combine documents as of OS X 10.5, so if you only need to do it once you can just drag the document where you want it in the sidebar of the main document.