Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ "$#" -ne 1 ]
- then
- echo "Output folder not specified"
- exit 1
- fi
- a=0
- b=0
- c=0
- for FILE in ./*.pdf; do
- ((a+=$(stat -c%s "${FILE}")))
- done
- for FILE in ./*.pdf; do
- gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dNOPAUSE -dBATCH -dQUIET -sOutputFile=temp.pdf "${FILE}"
- oldsize=$(stat -c%s "${FILE}")
- newsize=$(stat -c%s temp.pdf)
- if (("$newsize" < "$oldsize"))
- then
- ((c++))
- cp -f temp.pdf $1/"${FILE}"
- else
- cp -f "${FILE}" $1/"${FILE}"
- rm -f temp.pdf
- fi
- done
- for FILE in $1/*.pdf; do
- ((b+=$(stat -c%s "${FILE}")))
- done
- d=$(bc -l <<< "scale=2; (($a-$b))/1024")
- e=$(bc -l <<< "scale=2; 100*$b/$a")
- echo "Shrinked $c PDFs, saving $d kiB at $e% compression ratio."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement