Compressing a PDF file on macOS

Sometimes people create PDF files with large images, resulting in files that are too large to email or sometimes even upload on web forms.

A quick and dirty way to compress such files is using ghostscript in a terminal, which you can install on macOS using homebrew (brew install ghostscript):

gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/screen -dEmbedAllFonts=true -dSubsetFonts=true -dColorImageDownsampleType=/Bicubic -dColorImageResolution=192 -dGrayImageDownsampleType=/Bicubic -dGrayImageResolution=144 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=144 -sOutputFile="${1%.*}.compressed.pdf" myfile.pdf

Replace “myfile.pdf” with the file to compress.

For convenience, you can create a function:

pdfc() {
  command gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/screen -dEmbedAllFonts=true -dSubsetFonts=true -dColorImageDownsampleType=/Bicubic -dColorImageResolution=192 -dGrayImageDownsampleType=/Bicubic -dGrayImageResolution=144 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=144 -sOutputFile="${1%.*}.compressed.pdf" "$1"

Use like so:

pdfc myfile.pdf

And a smaller pdf file will be written to myfile.compressed.pdf.

This isn’t without cost. The resulting PDF file will contain lower resolution images which have less detail and will look worse zoomed in, but you can tweak the resolution settings to see what works for you. Generally I find the above settings acceptable for most documents at normal reading size. It will reduce a file with 3 large images captured with a phone from 6Mb to around 100Kb.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.