If you need to merge multiple PDF files on a Mac, most users turn to the built-in Preview app or rely on expensive third-party software like Adobe Acrobat. However, dragging and dropping pages in Preview can be incredibly tedious if you are dealing with dozens of massive PDF files. If you are comfortable using the terminal, you can merge an unlimited number of PDFs instantly using a hidden Python script that comes pre-installed on macOS.
How to Merge PDFs Using the Automator Script in Terminal
Deep inside the system library of macOS, Apple has hidden a Python utility specifically designed to join PDF files. By invoking this script from the Terminal, you can concatenate documents in a fraction of a second.
- Place all the PDF files you want to merge into a single folder (e.g., a folder named “Invoices” on your Desktop) to make things easier.
- Rename the files so they are in alphabetical or numerical order. The terminal will merge them in the exact order that they are listed.
- Open the Terminal app (found in Applications > Utilities).
- Use the
cdcommand to navigate to the folder containing your PDFs. For example:cd ~/Desktop/Invoices - Execute the following command, making sure to replace
output.pdfwith your desired final filename, and listing the specific PDFs you want to merge:/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py -o output.pdf file1.pdf file2.pdf file3.pdf
How to Merge All PDFs in a Directory at Once
If you have 50 PDFs in a folder and do not want to type out every single filename manually, you can use a wildcard (*.pdf) to tell the script to grab every PDF file in the current directory and merge them into one.
Run this command inside your folder:/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py -o Master_Document.pdf *.pdf
Press Return. The script will run silently, and within seconds, your new Master_Document.pdf will appear in the folder containing all the combined pages.