Last active
October 13, 2015 14:25
-
-
Save chintak/6f8a528a8aff44d7e9f7 to your computer and use it in GitHub Desktop.
Code to compress all the pdf files in a given directory.
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 | |
path="$1" | |
echo "Changing directory to $path." | |
cd "$path" | |
while IFS= read -r -d '' f; do | |
filename="${f##*/}" | |
path="${f%/*}" | |
new_file=temp_"${filename//\ /_}" | |
out_file="${filename//\ /_}" | |
echo "Moving:" $f "=>" $new_file | |
mv "$f" "$new_file" | |
echo "Compressing:" $new_file "=>" $out_file | |
echo | |
gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dPDFSETTINGS=/screen -dCompatibilityLevel=1.8 -sOutputFile="$out_file" "$new_file" | |
rm "$new_file" | |
done < <(find . -wholename '*.pdf' -print0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment