compress images in pdf files

30 06 2011

so this might be useful if you want to forward/store a pdf file (newsletter etc.) that contains uncompressed images. Using ghostscript you can resize them inside the pdf file.
$ pdfcompress inputfile.pdf outputfile.pdf

#!/bin/bash
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$2 $1
# more options:
# http://milan.kupcevic.net/ghostscript-ps-pdf/


With thanks to Milan Kupcevic for the inspiration. More options (especially regarding the image resolution) can be found on his page.