Read more

Compress bitmap images within PDF files

Thomas Eisenbarth
May 28, 2012Software engineer at makandra GmbH

Embedding bitmap images within PDF sometimes results in large files because the bitmaps are not compressed. If you don't need high quality images within the resulting PDF file, you can use ghostscript to compress embedded images:

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=new-smaller-file.pdf large-original-file.pdf
Illustration money motivation

Opscomplete powered by makandra brand

Save money by migrating from AWS to our fully managed hosting in Germany.

  • Trusted by over 100 customers
  • Ready to use with Ruby, Node.js, PHP
  • Proactive management by operations experts
Read more Show archive.org snapshot

Note that your PDF printer (or similiar generation tools) also often come with a compression setting for embedded raster images.

You can put this snippet into your ~/.bash_aliases:

alias pdf_compress='_compress(){ ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$1".c.pdf "$1";}; _compress'

Reload aliases (source ~/bash_aliases) and you can simply use pdf_compress example.pdf on your commandline.

Posted by Thomas Eisenbarth to makandra dev (2012-05-28 15:57)