Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
compress-scanned pdf files
#!/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
You can’t perform that action at this time.