Merge pdfs sequentially

pdf

I would like to merge 4 pdfs, pdf1.pdf, pdf2.pdf, pdf3.pdf pdf4.pdf together so that the pdfs are spliced, i.e. the first page will be the first page of pdf1, the second the first of pdf2, the third the first of pdf3, etc.

The pdf files are with plain images, no table of contents.

How would I accomplish this? It would be nice to do it from Terminal as well.

Best Answer

This can be done using a macOS default built-in, from either the command line or its GUI app the action belongs to.

To do as you requested from the command line, in Terminal, use the following command example:

"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" --shuffle -o /path/to/collated.pdf /path/to/file1.pdf /path/to/file2.pdf /path/to/file3.pdf /path/to/file4.pdf

To make the macOS built-in join.py script easier to use from the command line, I'd suggest you make a symbolic link for it. As an example, if you have /usr/local/bin in your PATH:

sudo ln -s "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" "/usr/local/bin/pdfjoin"

Afterwards, you can start the command with just pdfjoin instead of using its fully qualified pathname.


Below is a image of an Automator workflow to show an example of how it can be achieved using a macOS default built-in GUI app. Note that it can be modified many different ways to suit one's needs/wants.

enter image description here

Note: The Combine PDF Pages action, when used in Automator creates a temp file and why additional actions are needed to refine the workflow. You could just use the Open Finder Items action directly after and forgo the other actions, but of course you'll need to then manually save the opened new pdf file elsewhere.