Compressing PDF Files with Ghostscript

I shrank a 724 MB PDF to 29 MB with the open-source tool Ghostscript. Here are the command and options I used.


What is Ghostscript?

Ghostscript is an open-source interpreter for PostScript and PDF. It's used for PDF compression, conversion, and rendering. It's free and supports Windows, Mac, and Linux.


Installation

Download the installer from the official site and run it. (This post covers Windows.)

After installation, the executable will be at:

TEXT
C:\Program Files\gs\gs10.06.0\bin\gswin64c.exe

The Command

Bash
MSYS_NO_PATHCONV=1 "C:/Program Files/gs/gs10.06.0/bin/gswin64c.exe" \
  -sDEVICE=pdfwrite \
  -dCompatibilityLevel=1.4 \
  -dPDFSETTINGS=/ebook \
  -dNOPAUSE -dQUIET -dBATCH \
  -sOutputFile="output.pdf" "input.pdf"

Note for Git Bash on Windows: Arguments starting with /, like /ebook, get converted into Windows absolute paths, which breaks the command. Prepend MSYS_NO_PATHCONV=1 to prevent this.


Quality Settings

-dPDFSETTINGS sets the image resolution, which changes file size and quality:

OptionResolutionBest For
/screen72 dpiScreen viewing, smallest file size
/ebook150 dpiGeneral documents, balanced quality
/printer300 dpiPrint-ready documents
/prepress300 dpiPublishing, preserves color information

I used /ebook, and the quality was good enough for me.


Results

FileSize
Original724 MB
Compressed29 MB
Reduction96%

Wrapping Up

Ghostscript was easy to install, and one command shrank the PDF a lot. If quality matters, use /printer. If size is the priority, use /screen.