13 June 2021
How to programmatically combine & compress PDFs
Here’s a quick way to combine and compress PDF files via the command-line.
Combine files:
pdfunite *.pdf slides.pdf
Compress file:
gs -sDEVICE=pdfwrite -dCompatabilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -dColorImageResolution=150 -sOutputFile="slides-compressed.pdf" "slides.pdf"
Installation:
Easy peasy—but you might need to install some dependencies to make this work. The pdfunite
utility is part of the hefty poppler package and gs
is Ghostscript. On a mac with Homebrew you can install them via:
brew install poppler gs
Take a stretch break or make a cup of tea while poppler installs dependencies like imagemagick, ffmpeg, awscli, python, sqlite, and more. Or maybe with all these clamps and popplers, go watch an episode of Futurama.