Skip to content

Instantly share code, notes, and snippets.

@glenux
Created September 4, 2018 10:08
Show Gist options
  • Save glenux/5b68bddf2ccb0763f75904fc800e0419 to your computer and use it in GitHub Desktop.
Save glenux/5b68bddf2ccb0763f75904fc800e0419 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
set -u
INPUT="${1:-}"
OUTPUT="${2:-}"
if [ -z "$INPUT" ]; then
echo "ERROR: please give a input file name"
exit 1
fi
if [ -z "$OUTPUT" ]; then
OUTPUT="$(echo "$INPUT" |sed -e 's/\.pdf$/.optim.pdf/')"
fi
# either screen, print or ebook
QUALITY="${3:-screen}"
case "$QUALITY" in
print|screen|ebook) ;;
*) echo "ERROR: quality must be one of screen|ebook|print"
exit 1
esac
gs -sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
"-dPDFSETTINGS=/$QUALITY" \
-dNOPAUSE \
-dQUIET \
-dBATCH \
"-sOutputFile=$OUTPUT" \
"$INPUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment