Skip to content

Instantly share code, notes, and snippets.

@lucacerone
Created February 26, 2014 13:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucacerone/9229366 to your computer and use it in GitHub Desktop.
Save lucacerone/9229366 to your computer and use it in GitHub Desktop.
Simple bash script to compress pdf files using Ghostscript
#!/usr/bin/env bash
# Compress a pdf using gs.
# Requires in input the compression type, the name of the file to compress and the name of the output file (in this order).
# Example:
# pdfcompress screen MyHighResDocument.pdf MyLowResDocument.pdf
#
# Possible values for compression types are:
# 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
#
# link: http://lucacerone.net/2014/01/reduce-pdf-size-from-command-line/
COMMAND="gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/$1 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=\"$3\" \"$2\""
echo $COMMAND
sh -c "$COMMAND"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment