I have 1000 groups of 5 pdf files I need to combine/merge. I aware of the "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" command and have created the 1000 different versions of the command I need. Currently I am copying and pasting each separate line into Terminal to run it. Is there a way to put all 1000 lines into a script and run the script. Thanks

  • Can you add a few samples of your code to the question?
    – nohillside
    Mar 29 '18 at 4:11
  • Also, how can the five files to be merged be identified? Do they have specific names, are in a specific directory, or something else?
    – nohillside
    Mar 29 '18 at 4:13
  • @patrix All the files are in the one directory, they have specific names and a unique merge file name, there are actually more than 5 files as you will see from the lines below. Mar 29 '18 at 6:08
  • @patrix "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" -o 71290-Leung-HeiTung-Bernice_5-2-2017.pdf Leung-HeiTung-Bernice_5B-aaY5B-EDITED.pdf Leung-HeiTung-Bernice_5B-ART5BFINAL.pdf Leung-HeiTung-Bernice_5B-CE5Bfinal.pdf Leung-HeiTung-Bernice_5B-DRY5B-FINAL.pdf Leung-HeiTung-Bernice_5B-FRYR5BFINAL.pdf Leung-HeiTung-Bernice_5B-LIB5B.pdf Leung-HeiTung-Bernice_5B-MUY5BEdited2017.pdf Leung-HeiTung-Bernice_5B-PE5BFinal.pdf Not enough characters to add another line, but they all have the same format. Mar 29 '18 at 6:12
  • Please edit your question to include this information, it‘s too hard to read as a comment. Also, how do names of which belong together differ from names who don‘t? Any programmatic solution will need to follow some rules to combine the right files
    – nohillside
    Mar 29 '18 at 7:02

The functionality to combine PDFs is built into Preview.app, and this can be a handy approach for dealing with small numbers of documents.

Recent versions of macOS also have a Python script that automates this process for multiple PDF files. This script is located at:

/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py

You can run the script directly in Terminal, but it might be handy to add an alias in your ~/.bash_profile:

alias combinepdfs='/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py'

Instead of typing the long location to the script every time, now you can run this script using a single command! (Don't forget to reload after making changes: source ~/.bash_profile.)

Say I have a directory of lecture notes ~/Documents/Lectures that contains the following files:

lec2.pdf  lec3.pdf  lec4.pdf  lec5.pdf  lec6.pdf  lec7.pdf  lec8.pdf  lec9.pdf lec10.pdf lec11.pdf lec12.pdf lec13.pdf lec14.pdf lec15.pdf lec16.pdf lec17.pdf 

I can combine these PDF files using the following command:

$ combinepdfs -o lec-combined.pdf lec{2..17}.pdf

The general usage pattern is listed in the help command:

$ combinepdfs --help

Usage: join [--output <file>] [--shuffle] [--verbose]

There is also an extra feature to shuffle pages:

#       Take a page from each PDF input file in turn before taking another from each file.
#       If this option is not specified then all of the pages from a PDF file are appended
#       to the output PDF file before the next input PDF file is processed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .