Blog‎ > ‎

Optimize a PDF or extract part of it with ghostscript

posted Nov 9, 2015, 11:58 AM by Juan Jose Garcia-Ripoll   [ updated Nov 9, 2015, 11:59 AM ]
I am writing some largish lecture notes, which now are around 120 pages long. The problem with this document is that it is full of attractive images that are needed to make the content more clear and amenable, and these images are not optimized in size: they come from papers, simulations, drawings, etc, and each of them has been produced with different means and the final size of the image might be much smaller than what the resolution allows for.

So, the result is that I have this large file which is 16Mb large, which I will call notes.pdf I need to send a few chapters of this file to my colleagues and students and when I cut the file, it still is too large, 12-13Mb, as Adobe or OS X are not  able to really trim the size.

Here is what you can do:
  1. If you run Windows, install Ghostscript, either directly (look for it) or from Cygwin.
  2. Open a command line and type
gs -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -sOutputFile=small-notes.pdf notes.pdf
 
This reduces the size quite significantly by (i) reducing the size of figures to the resolution that is needed for the given device (screen), (ii) eliminating fonts that are already standard and which are included by PDFLaTex, (iii) compressing the output. In my case, down from 34Mb to 13Mb.

If I need to select a few pages, tell that to Ghostscript:

gs -dFirstPage=1 -dLastPage=73 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dBATCH -dNOPAUSE -dPDFSETTINGS=/screen -sOutputFile=small-notes.pdf notes.pdf