Created
November 25, 2014 14:20
-
-
Save scriptum/340f3ef2682f6eb6362a to your computer and use it in GitHub Desktop.
PDF optimization script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for f in "$@" | |
do | |
TMP=$(mktemp) | |
SIZE_OLD=$(wc -c < "$f") | |
echo "Optimizing '$f' of size $SIZE_OLD" | |
/usr/bin/gs \ | |
-sDEVICE=pdfwrite \ | |
-dCompatibilityLevel=1.4 \ | |
-dPDFSETTINGS=/ebook \ | |
-dNOPAUSE \ | |
-dBATCH \ | |
-dQUIET \ | |
-sOutputFile="$TMP" \ | |
"$f" | |
SIZE_NEW=$(wc -c < "$TMP") | |
if [ $(echo "$SIZE_NEW > $SIZE_OLD" | bc) = "1" ] | |
then | |
echo "New size ($SIZE_NEW) is bigger, skipping" | |
rm "$TMP" | |
else | |
echo "New size: $SIZE_NEW" | |
mv "$f" "$f".bak | |
mv "$TMP" "$f" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment