can I combine PDF files using a command line?

I see that preview can combine PDF files using the edit>insert>insert from files technique that I found in Apple support. I'd like to create a command file to do this for a whole bunch of files. Is there a way to do this from the command line? Thanks.

Mac mini, macOS 12.3

Posted on May 19, 2022 6:27 AM

Reply
1 reply

May 19, 2022 11:40 AM in response to bryante

Unless you are a developer, then the answer is no, and particularly no after macOS 12.3.1 where Apple has removed the Python 2.7.18 distribution which gave one access to the relevant development frameworks for manipulating PDFs programmatically from the command line.


While still using macOS 12.3, or earlier, one can "borrow" the join.py script found in the Automator Combine PDF Pages action by either linking to it, or copying it to your Desktop. From Finder, press shift+command+G and copy/paste the following path into that dialog:


/System/Library/Automator/Combine PDF Pages.action/Contents/Resources


Just drag join.py to your Desktop. It's usage is in its comments. The join.py script uses CoreGraphics frameworks and is not Python3 compatible.


Another approach that is not dependent on Python is to use osascript to run an AppleScript-Objective-C application from the Terminal that has been designed to pluck PDF document names that you provide on the command-line:


/usr/bin/osascript merge_pdf_cmd.applescript pdf1.pdf pdf2.pdf ... pdfn.pdf


and a third approach is to compile Swift source code that performs a PDF merge and then use that executable from the command line with a list of PDFs as shown above.


The last two approaches I can post here, though the former is being converted from a GUI solution to command line, and the latter requires that one has installed the Command Line Tools for Xcode which gives you the swift compiler or interpreter. The following command does not install the monster Xcode product:


xcode-select --install



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

can I combine PDF files using a command line?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.