From c9c896dea2ba43551c4e10bd49666105449e9bd7 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Thu, 31 Mar 2016 10:57:34 +0800 Subject: add all scripts/tools --- cli/shrinkpdf.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 cli/shrinkpdf.sh (limited to 'cli/shrinkpdf.sh') diff --git a/cli/shrinkpdf.sh b/cli/shrinkpdf.sh new file mode 100755 index 0000000..1190fce --- /dev/null +++ b/cli/shrinkpdf.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# +# Shrink the size of PDF files by adjust its quality using gs. +# +# Aaron LI +# 2013/09/18 +# + +case "$1" in + -[hH]*|--[hH]*) + printf "usage:\n" + printf " `basename $0` in= out= quality= imgdpi=\n" + exit 1 + ;; +esac + +getopt_keyval() { + until [ -z "$1" ] + do + key=${1%%=*} # extract key + val=${1#*=} # extract value + keyval="${key}=\"${val}\"" + echo "## getopt: eval '${keyval}'" + eval ${keyval} + shift # shift, process next one + done +} +getopt_keyval "$@" + +if [ -z "${in}" ] || [ -z "${out}" ]; then + printf "Error: 'in' or 'out' not specified\n" + exit 2 +fi +quality=${quality:-ebook} +imgdpi=${imgdpi:-120} + +printf "# in: ${in} +# out: ${out} +# quality: ${quality} +# imgdpi: ${imgdpi}\n" + +gs -dNOPAUSE -dBATCH -dSAFER \ + -sDEVICE=pdfwrite \ + -dCompatibilityLevel=1.4 \ + -dPDFSETTINGS="/${quality}" \ + -dEmbedAllFonts=true \ + -dSubsetFonts=true \ + -dColorImageDownsampleType=/Bicubic \ + -dColorImageResolution=${imgdpi} \ + -dGrayImageDownsampleType=/Bicubic \ + -dGrayImageResolution=${imgdpi} \ + -dMonoImageDownsampleType=/Bicubic \ + -dMonoImageResolution=${imgdpi} \ + -sOutputFile=${out} \ + ${in} + -- cgit v1.2.2