Compress PDF in Mac using command line (for free)

1 minute read

Compressing a PDF in Mac is very easy and doesn’t require any of the commercial tools out there. This isn’t an area I normally blog about, but when I needed this, I couldn’t find any useful information on how to do this on a Mac. All you have to do is install Macports and from there install ghostscript:


jos@Joss-MacBook-Pro.local:~$ sudo port install ghostscript
...
--->  Activating ghostscript @9.05_1
--->  Cleaning ghostscript

You’ll see a whole lot of text scrolling by, but at the end you’ll have an installed version of ghostscript. Now you can easily compress PDFs by just using the following command:


jos@Joss-MacBook-Pro.local:~$ gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 
                    -dPDFSETTINGS=/ebook -dNOPAUSE 
                    -dQUIET -dBATCH 
                    -sOutputFile=/Users/jos/Desktop/scan-1-small.pdf /Users/jos/Desktop/scan-1.pdf

This will convert the file “scan-1.pdf” to “scan-1-small.pdf”. In this example this reduces the file size from 8.6MB to 600KB. You can define various quality settings by using a different value for the -dPDFSETTINGS option. From the ghostscript documentation you have the following options:


/screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
/ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
/printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
/prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.
/default selects output intended to be useful across a wide variety of uses, 
            possibly at the expense of a larger output file.

So you see, you don’t need expensive commercial tools, just to resize a PDF, just use open source.

Updated: