Compressing papers with ghostscript

5 May 2017 in research

When searching for ways to compress the size of a ~50MB paper pdf, I’ve discovered the following ghostscript command (askUbuntu, TeX StackExchange)

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed.pdf original.pdf

Argument of -dPDFSETTINGS can be any of:

-dPDFSETTINGS=/screen   # lower quality, smaller size.
-dPDFSETTINGS=/ebook    # for better quality, but slightly larger pdfs.
-dPDFSETTINGS=/prepress # output similar to Acrobat Distiller "Prepress Optimized" setting
-dPDFSETTINGS=/printer  # selects output similar to the Acrobat Distiller "Print Optimized" setting

(descriptions copy-pasted from askUbuntu)

I wrote a small script to test the different -dPDFSETTINGS modes.

declare -a pdfsettings=("screen" "ebook" "prepress" "printer" "default")
args="-sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH"
for mode in "${pdfsettings[@]}"
    # output file
   # compress with ghostscript
   gs $args -dPDFSETTINGS=/$mode -sOutputFile=$ofile $file.pdf
   # print size of the compressed file
   du -h $ofile
# output
912K	compressed/paper.screen.pdf
1.2M	compressed/paper.ebook.pdf
3.4M	compressed/paper.prepress.pdf
2.6M	compressed/paper.printer.pdf
9.9M	compressed/paper.default.pdf

comparison of gs pdf compression modes