A Suggestion to the Prawn development team on making smaller PDF files

One of my favourite features of the PDF file format is its flexibility. You can do just about anything with it. However, a drawback to this is that it does not always get used to best effect.

I was investigating a PDF file issue today for our Java PDF renderer. The issue turned out to be that the PDF file contained an image encoded in 16 bit RGB format. Here is the object information in Acrobat.

PDF file format lets you choose a resolution for your images (anything from 1 to 32 bits). Most RGB images use 8 bit as a trade-off between quality and size. I actually cannot recollect ever seeing a 16bit image in 11 years. I actually deal with the image by down-sampling it to 8 bit and there is no loss in visual quality.

The image in question is actually black and white so rather than 16bit RGB, it could have been encoded in Gray or Binary. This would reduce the size of the image data by a factor of up to 48!

The PDF file format provides lots of useful features but it does need careful consideration of how the features are used. You can see what a difference it can make to the size of the data which also affects load time. It is equally possible to create bloated, slow or fast, compact PDF files. Prawn looks very promising and I hope the developers look in detail at the PDF spec to see what useful tricks it offers.

This post is part of our “Understanding the PDF File Format” series. In each article, we discuss a PDF feature, bug, gotcha or tip. If you wish to learn more about PDF, we have 13 years worth of PDF knowledge and tips, so click here to visit our series index!

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

2 thoughts on “A Suggestion to the Prawn development team on making smaller PDF files

  1. James Healy

    Interesting timing. I’m on the prawn development team and have recently been cleaning up our PNG code. Your suggestion makes sense, I’ll update the code to embed 16 bit files as 8 bit.

  2. You could also add 1bit for black and white which would reduce filesize.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>