Is there a quick one-liner to combine multiple pdfs into one?

I know it can be done using Preview.app

up vote 38 down vote accepted

Have a look at "Combining PDF files on the command line in OSX" in Joining PDF Files in OS X From the Command Line.

It turns out that from Tiger onwards, OSX ships with a Python script that does exactly what you need. The script is already executable, and Python is pre-installed on OS X, so all you need to do to run it is opening the Terminal and typing

"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" -o PATH/TO/YOUR/MERGED/FILE.pdf /PATH/TO/ORIGINAL/1.pdf /PATH/TO/ANOTHER/2.pdf /PATH/TO/A/WHOLE/DIR/*.pdf

Also on the linked page it suggests making a symbolic link for the join.py file to make typing easier however they omitted the -s in ln -s ... ..., and without it, a hard link is created. Probably wouldn't matter, however though I'd mention it.

Just install Ghostscript using Brew with command:

brew install gs

Then run command with all files listed:

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf source1.pdf source2.pdf source3.pdf
  • OS X/macOS already natively has a way to combine PDF files from the command line, so why waste the time of having to first install Command Line Tools for Xcode, Homebrew and then Ghostscript, to do something that can already be done natively without having to install any of the aforementioned packages? – user3439894 Jul 27 '17 at 20:34
  • 3
    @user3439894 many people already have these common packages installed and are already using gs so for future reference this solution would be just as convenient. – htor Dec 6 '17 at 15:26
  • 1
    @user3439894 i see the confusion. i'm addressing you because you were questioning the value of this answer. using homebrew to install command line utilities is very common these days, so i wouldn't call it a waste of time. for many people this answer provides an equally good solution as yours. – htor Dec 6 '17 at 17:05
  • 3
    this worked for me, the py command didn't – Thieme Hennis Mar 27 at 20:23
  • 1
    As per Thieme Hennis' comment, the join.py script crashes for me in High Sierra with a segmentation fault. But gs works perfectly. – arcdale May 24 at 8:06

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.