Skip to content

Instantly share code, notes, and snippets.

@tatome
Forked from danmackinlay/shrinkpdf.sh
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatome/8880839 to your computer and use it in GitHub Desktop.
Save tatome/8880839 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -lt 2 ] || [ $# -gt 3 ]; then
echo usage: shrinkpdf \<filename\> \<resolution\> \[\<output\>\]
exit
fi
if [ ! -e "$1" ]; then
echo "$1" does not exist. Exiting.
exit
fi
if [ $# = 3 ]; then
NEWNAME=$3
else
NEWNAME=`basename $1 .pdf`_shrinked.pdf
fi
if [ "$1 " = "$NEWNAME " ]; then
echo Input and output are identical. Won\'t overwrite---exiting.
exit
fi
if [ -e "$NEWNAME" ]; then
echo "$NEWNAME" exists. Delete? \(y/n\)
read ANS
if [ "$ANS " = "y " ]; then
rm "$NEWNAME"
else
exit
fi
fi
gs -q -dNOPAUSE -dBATCH -dSAFER \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.3 \
-dPDFSETTINGS=/screen \
-dEmbedAllFonts=true \
-dSubsetFonts=true \
-dColorImageDownsampleType=/Bicubic \
-dColorImageResolution=$2 \
-dGrayImageDownsampleType=/Bicubic \
-dGrayImageResolution=$2 \
-dMonoImageDownsampleType=/Bicubic \
-dMonoImageResolution=$2 \
-sOutputFile="$NEWNAME" \
"$1"
echo $1: $((`wc -c "$1" | cut -d \ -f 1` / 1024 )) kb
echo $NEWNAME: $((`wc -c "$NEWNAME" | cut -d \ -f 1` / 1024 )) kb
@tatome
Copy link
Author

tatome commented Feb 8, 2014

Heh, I wrote this years ago, modifying a script by Alfred Klomp. It's really not rocket science, but apparently demand is high for this sort of thing: people kept coming to my site even though the script had disappeared from it for a long time.

Now I found @howthebodyworks had made a Gist of it. I've forked it and will link to it from my site again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment