Skip to content

Instantly share code, notes, and snippets.

@almirb
Forked from guifromrio/compress-pdf-with-gs.md
Last active November 26, 2023 09:13
Show Gist options
  • Save almirb/1ea3de8b2ad6a332f153a4f2eff1ce89 to your computer and use it in GitHub Desktop.
Save almirb/1ea3de8b2ad6a332f153a4f2eff1ce89 to your computer and use it in GitHub Desktop.
Compress PDF files with ghostscript

Batch Compress PDF

This can reduce files to ~15% of their size (2.3M to 345K, in one case) with no obvious degradation of quality. With this file you'll able to compress a bunch of PDF files at once.

Usage

First, download and install Ghostpdf (https://ghostscript.com/download/). From command prompt, run compress-pdf.md "source folder" "destination folder" e.g:

compress-pdf.md "C:\Pdf" "C:\PdfCompressed" 

If you want to compress only one file at time:

ghostscript -sDEVICE=pdfwrite -dMaxSubsetPct=100 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Other options for PDFSETTINGS:

  • /screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
  • /ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
  • /printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
  • /prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.
  • /default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file.

Source: http://ghostscript.com/doc/current/Ps2pdf.htm

for /R "%1" %%f in (*.pdf) do (
gswin64c.exe -sDEVICE=pdfwrite -dMaxSubsetPct=100 -dPDFSETTINGS=/ebook -sOutputFile="%~2%%~nxf" -dNOPAUSE -dBATCH "%%f"
)

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