Skip to content

Instantly share code, notes, and snippets.

@shanecelis
Created May 6, 2013 20:23
Show Gist options
  • Save shanecelis/5527887 to your computer and use it in GitHub Desktop.
Save shanecelis/5527887 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# shrinkpdf
#
# Shane Celis
if [ $# -ne 1 ] && [ $# -ne 2 ]; then
echo "usage: shrinkpdf <in.pdf> [out.pdf]" >&2;
echo "Shrink the size of the given PDF. By default it outputs to file 'out.pdf'." >&2;
exit 2;
fi
in="$1";
out=out.pdf;
if [ $# -eq 2 ]; then
out="$2";
fi
resolution=300;
gs -q -dNOPAUSE -dBATCH -dSAFER \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.3 \
-dPDFSETTINGS=/screen \
-dEmbedAllFonts=true \
-dSubsetFonts=true \
-dColorImageDownsampleType=/Bicubic \
-dColorImageResolution=$resolution \
-dGrayImageDownsampleType=/Bicubic \
-dGrayImageResolution=$resolution \
-dMonoImageDownsampleType=/Bicubic \
-dMonoImageResolution=$resolution \
-sOutputFile="$out" \
"$in"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment