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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)