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:
C:\Program Files\gs\gs10.06.0\bin\gswin64c.exe
The Command
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. PrependMSYS_NO_PATHCONV=1to prevent this.
Quality Settings
-dPDFSETTINGS sets the image resolution, which changes file size and quality:
| Option | Resolution | Best For |
|---|---|---|
/screen | 72 dpi | Screen viewing, smallest file size |
/ebook | 150 dpi | General documents, balanced quality |
/printer | 300 dpi | Print-ready documents |
/prepress | 300 dpi | Publishing, preserves color information |
I used /ebook, and the quality was good enough for me.
Results
| File | Size |
|---|---|
| Original | 724 MB |
| Compressed | 29 MB |
| Reduction | 96% |
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.