I have previously written about a shell script) for compressing PDF files in Ubuntu. Here are some variants of the script.
Low, mid, and high resolution
Low resolution for screen:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.6 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf in.pdf
I prefer the “ebook” mode, which has slightly higher resolution:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.6 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf in.pdf
And then there is the high resolution for printing:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.6 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf in.pdf
Since I don’t need to print things very often, I generally find the “ebook” mode to be a good balance between size and quality.
Batch scripting
Here are some scripts for batch processing multiple files. One for the “ebook” mode:
for i in *.pdf; do name=`echo $i | cut -d'.' -f1`; gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.6 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="${name}_ebook.pdf" "$i"; done
And one for printing:
for i in *.pdf; do name=`echo $i | cut -d'.' -f1`; gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.6 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile="${name}_printer.pdf" "$i"; done
The commands are tricky to remember, but easy to copy into a terminal.