Reduce the file size of PDFs with Ghostscript

Posted on

Portable Document Format (PDF) is a common format used for publishing maps. PDFs can contain both raster and vector data and can be read by a large number of freely available viewer applications, such as Adobe Reader and Okular.

Adobe Reader Pro can be used to optimize the size of PDF files, by selecting File > Save As... > Optimized PDF. However, Adobe Reader Pro isn’t free, and isn’t easily automated.

The Ghostscript command line tool can also be used to reduce the size of PDF files.

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Ghostscript can be called from Python using the subprocess module, and used from scripts working with arcpy or QGIS.