Skip to content

Instantly share code, notes, and snippets.

@janosh
Last active November 18, 2018 15:15
Show Gist options
  • Save janosh/62f4a4bf01627814c12a862a20338a63 to your computer and use it in GitHub Desktop.
Save janosh/62f4a4bf01627814c12a862a20338a63 to your computer and use it in GitHub Desktop.
Bash script, accepts directory as single argument, recursively compresses all PDFs in there and subdirectories, uses ghostscript, appends -min to name of compressed file
#!/bin/bash
find "$1" -name "*.pdf" | while read file; do
path=${file%/*}
basename=${file##*/}
ext=${basename##*.}
filename=${basename%.*}
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -dQUIET -sOutputFile="$path/$filename-min.pdf" "$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment