Combining PDFs on Mac
I often need to combine PDFs when I do my weekly planning. As a Windows user I didn’t have an easy way of doing it (free applications generealy come with bloatware) so I developed myself a small console applicaiton in C# to merge PDFs into one. As I decided to switch to Mac for daily usage I was again in need to achieve the same task. Fortunately, the solution is built-in to Mac already.
Apparently, the PDF preview tool allows you to drag and drop other documents as pages so it’s an easy way of doing it. But I wanted to automate the process and found this article which shows how to do it via command line.
So here how it works:
Basically there’s a Python script that is shipped with OSX which does the job:
"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" -o Output.pdf /SomePath/Input1.pdf /SomePath/Input2.pdf /SomePath/*.pdf
This is it essentially. To make it a bit easier a soft link can be created
cd /usr/local/bin sudo ln -s "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" PDFconcat
In the article the symlink parameter (-s) is not mentioned and I was getting “Operation not permitted” error without it. I found this parameter in the comments section. It worked this way.
So now the usage becomes much simpler:
./PDFconcat -o Week.pdf ./Days/*.pdf
Looks like the order of the parameters matter. For instance the following doesn’t work
./PDFconcat ./Days/*.pdf -o week.pdf
It doesn’t show any errors but just doesn’t produce the output either.