How to Merge PDF Files in macOS Terminal with qpdf
For merging existing PDFs in Terminal, I now use qpdf. The original version of this post used an Automator join.py script inside macOS. That script is absent on the Mac I checked in October 2026, so this guide now uses a tool you can install explicitly.
If you are starting with photos or screenshots, use the separate guide to creating a PDF from images.
Install qpdf
With Homebrew installed, run:
brew install qpdf
Check the installation:
qpdf --version
Merge two PDF files
Go to the folder containing your PDFs in Terminal, then run:
qpdf --empty --pages first.pdf second.pdf -- merged.pdf
The result contains the pages from first.pdf, followed by those from second.pdf. --empty starts a new document, and the final -- separates the input pages from the output filename.
Put quotes around filenames with spaces:
qpdf --empty --pages "first file.pdf" "second file.pdf" -- merged.pdf
Merge a folder of PDFs
qpdf --empty --pages *.pdf -- ../merged.pdf
The shell supplies files in filename order. Number them 01-cover.pdf, 02-details.pdf, and so on if order matters. This example saves the result in the parent folder, keeping it out of the input wildcard when you run the command again.
Take only the pages you need
qpdf --empty --pages first.pdf 1 second.pdf 1-2 -- selected.pdf
This takes page 1 from the first PDF, then pages 1–2 from the second. The result has three pages.
qpdf copies PDF pages without rendering them as images. Document-level features such as bookmarks and forms need extra care when merging; check the finished document if they matter. The qpdf page-selection documentation explains the options and limitations.
I checked these examples with qpdf 12 on macOS in October 2026, including the resulting page counts and PDF validity.