Add bin/pdfoptim

This commit is contained in:
Henrik Lissner 2017-07-14 15:56:47 +02:00
parent 1082a22197
commit 4ebe18eb8b
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

36
bin/pdfoptim Executable file
View file

@ -0,0 +1,36 @@
#!/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"
}
SRC="$1"
DEST="${2:--}"
DPI="${3:-72}"
optimize "$SRC" "$DEST" "$DPI" || exit $?