Created
July 16, 2018 08:21
-
-
Save aytacworld/849a3b74009b641e9ad35fc0da2d3ddb to your computer and use it in GitHub Desktop.
compress-scanned pdf files
This file contains 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
#!/bin/bash | |
if [ -z "${1}" ]; then | |
echo "please use it as 'compress-pdf <filename>'" | |
else | |
FILE=$1 | |
NEW_FILE=${FILE}.new.pdf | |
echo compressing $FILE | |
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="${NEW_FILE}" "${FILE}" | |
ORIG_SIZE=$(ls "$FILE" -s | cut -d " " -f 1) | |
NEW_SIZE=$(ls "${NEW_FILE}" -s | cut -d " " -f 1) | |
if [ $ORIG_SIZE -lt $NEW_SIZE ]; then | |
rm "${NEW_FILE}" | |
else | |
mv "${FILE}" "${FILE}.original" | |
mv "${NEW_FILE}" "${FILE}" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment