Skip to content

Instantly share code, notes, and snippets.

@ptheywood
Last active April 18, 2024 14:53
Show Gist options
  • Save ptheywood/bf0cba769d601538a0ba to your computer and use it in GitHub Desktop.
Save ptheywood/bf0cba769d601538a0ba to your computer and use it in GitHub Desktop.
Instructions for PDF compression via Ghostscript on Windows

Ghostscript PDF compression on Windows

Installation

  1. Download and install Ghostscript for windows (http://downloads.ghostscript.com/public/gs916w32.exe)
  2. Optional - Add the ghostscript directory to the path environment variable
    • Control Panel > System > Advanced System Settings > Environment Variables
    • Add ;C:\Program Files (x86)\gs\gs9.16\bin to th end of the PATH variable

Usage

  1. Open CMD & Navigate to the correct folder

    • Alternatively shift+right click in the correct folder on windows explorer > Open command window here
  2. Set the local path to include the GS binaries (If not set globally) SET PATH=%PATH%;C:\Program Files (x86)\gs\gs9.16\bin

  3. Use the following command to compress source.pdf into compressed.pdf (Change as required)

    gswin32c -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed.pdf source.pdf
    

Quality vs Filesize

It is possible to further reduce filesize by lowering quality using the -dPDFSETTINGS argument with values of /ebook or /screen, however this severely reduced image quality for the example PDF I tried.

gswin32c -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed.pdf source.pdf


gswin32c -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed.pdf source.pdf
@SaberGameDev
Copy link

Literally just saved me missing a deadline for a report, thank you so so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment