Understanding the PDF File Format: Filter and DecodeParms Objects for a PDF Image

One of the hardest things I found to get to grips with on the PDF File format was using filters and DecodeParams together. So let us look at some examples to see  how they work.

Here is the PDF object dump for an Image object in a PDF file (which uses a /Filter to compress the data and a /DecodeParms to contain values for that filter.

<< /DecodeParms [<< /BlackIs1 true /K -1 /Rows 3300 /Columns 2560 >>]
/Type /XObject
/Subtype /Image
/ColorSpace [/Indexed /DeviceRGB 1 ]
/Width 2560
/BitsPerComponent 1
/Length 45 0 R
/Height 3300
/Filter [ /CCITTFaxDecode]
>>
stream

It could also be written coded with the DecodeParms in a separate object like this

<<
/DecodeParms [44 0 R]
/Type /XObject
/Subtype /Image
/ColorSpace [/Indexed /DeviceRGB 1 ]
/Width 2560
/BitsPerComponent 1
/Length 45 0 R
/Height 3300
/Filter [ /CCITTFaxDecode]
>>
stream

44 0 obj
<<
/BlackIs1 true
/K -1
/Rows 3300
/Columns 2560
>>
endobj

So far so good. The Image has a /CCITT filter which uses some values stored in /DecodeParams (either directly or as an object).

But the image can have a more than one filter, in which case there needs to be a decodeParms for each example. In which case they are both arrays of values.

<<
/DecodeParms [43 0 R 44 0 R]
/Type /XObject
/Subtype /Image
/ColorSpace [/Indexed /DeviceRGB 1 ]
/Width 2560
/BitsPerComponent 1
/Length 45 0 R
/Height 3300
/Filter [/A85 /CCITTFaxDecode]
>>
stream

43 0 obj
<<
>>
endobj
44 0 obj
<<
/BlackIs1 true
/K -1
/Rows 3300
/Columns 2560
>>
endobj

So in this case, object 43 0 is the decodeParms value for /A85 filter and object 44 0 is the decodeParms for the /CCITT filter. Because /A85 does not take any values, but we still need a decodeParms for each filter we end up with an empty object. As you can imagine we had a  lot of fun getting our PDF parser to handle all these cases properly!

It works but it is a clunky mechanism – I would much prefer to have seen all the values in the single FIlter object which would have made it simpler to use and avoided these clunky cases. What do you think? Does it have any real advantages?

This post is part of our “Understanding the PDF File Format” series. In each article, we aim to take a specific PDF feature and explain it in simple terms. 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.

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>