helm/bin/optimpdf

37 lines
811 B
Plaintext
Raw Permalink Normal View History

2017-07-14 06:56:47 -07:00
#!/usr/bin/env bash
# Compress pdf files using ghostscript.
#
# Defaults to 72 dpi.
#
# Usage:
# pdfoptim SRC [TARGET] [DPI]
#
# Requires: ghostscript (gs)
optimize() {
# Adapted from Alfred Klomp's shrinkpdf script
# <http://alfredklomp.com/programming/shrinkpdf/>
gs -q -dNOPAUSE -dBATCH -dSAFER \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/screen \
-dCompatibilityLevel=1.3 \
-dEmbedAllFonts=true \
-dSubsetFonts=true \
-dAutoRotatePages=/None \
-dMonoImageResolution=$3 \
-dMonoImageDownsampleType=/Bicubic \
-dGrayImageResolution=$3 \
-dGrayImageDownsampleType=/Bicubic \
-dColorImageResolution=$3 \
-dColorImageDownsampleType=/Bicubic \
-sOutputFile="$2" \
"$1"
2017-07-14 06:56:47 -07:00
}
src="$1"
dest="${2:--}"
dpi="${3:-72}"
2017-07-14 06:56:47 -07:00
optimize "$src" "$dest" "$dpi" || exit $?