Skip to content

Instantly share code, notes, and snippets.

@atelierbram
Last active September 15, 2025 08:39
Show Gist options
  • Save atelierbram/5c0834fe884e4fd081c42b1b029b6fd3 to your computer and use it in GitHub Desktop.
Save atelierbram/5c0834fe884e4fd081c42b1b029b6fd3 to your computer and use it in GitHub Desktop.
Compress PDF with ghostscript from commandline
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed.pdf input.pdf

Settings for Ghostscript CLI - compress pdf

1. /prepress

This is the best setting for high-quality printing.

Purpose: Maintains the quality required for professional printing processes.

Features:

  • Images are uncompressed or compressed with a very low compression ratio.
  • The resolution is reduced to 300 dpi (dots per inch) for color and grayscale images.
  • Images are not reduced if they are already below 300 dpi.

2. /default

This option is the default setting and offers a good balance between file size and quality.

Purpose: General use, suitable for both digital and print.

Features:

  • Images are reduced to 150 dpi for color and grayscale images.
  • The compression is moderate and results in a significant file size reduction.

3. /ebook

This setting is optimized for on-screen viewing, such as on an e-reader or tablet.

Purpose: Minimum file size for digital distribution.

Features:

  • Images are downscaled to 150 dpi for color and grayscale images.
  • Uses stronger compression, which may result in a noticeable loss of image quality.

4. /screen

This is the most aggressive compression option.

Purpose: For viewing on screen, but with an emphasis on the smallest possible file size.

Features:

  • Images are downscaled to 72 dpi, which is the standard resolution for most screens.
  • Uses very strong compression, which may result in low image quality but results in the smallest file size.

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed-default.pdf input.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment