Skip to content

Instantly share code, notes, and snippets.

@chintak
Last active October 13, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chintak/6f8a528a8aff44d7e9f7 to your computer and use it in GitHub Desktop.
Save chintak/6f8a528a8aff44d7e9f7 to your computer and use it in GitHub Desktop.
Code to compress all the pdf files in a given directory.
#!/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