Skip to content

Instantly share code, notes, and snippets.

@rbnvrw
Created April 23, 2021 08:40
Show Gist options
  • Save rbnvrw/a047887fbc0a9da808826ac74fb749bc to your computer and use it in GitHub Desktop.
Save rbnvrw/a047887fbc0a9da808826ac74fb749bc to your computer and use it in GitHub Desktop.
Compress PDF using ghostscript for online publication of a large book (e.g. a PhD thesis)
#!/bin/bash
# input file
INFILE=thesis.pdf
# output file
OUTFILE=thesis_compressed.pdf
# /printer compresses to ~300 DPI, various optimizations
# -dPrinted=false preserves PDF hyperlinks
# Other properties set the resolution of the images to 200DPI, which is too small for printing but good enough for showing on a screen
ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -dPrinted=false -dDetectDuplicateImages -dDownsampleColorImages=true -dDownsampleGrayImages=true -dDownsampleMonoImages=true -dGrayImageResolution=200 -dColorImageResolution=200 -dMonoImageResolution=400 -sOutputFile="${OUTFILE}" "${INFILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment