Interesting PDF bugs – using SMask and image ‘the opposite way’ round

Not sure if this is strictly a bug but it is certainly an ‘interesting’ way to use the PDF spec and unduly complex.

When you create an image in a PDF, you can also give it an SMask (a stencil which allows you to only show part of the image). So far so good….

Have a look at this image as shown in the PDF Object viewer in Adobe acrobat.

This image has an indexed Colorspace with just 1 colour defined and the image itself is a solid block of data. The actual image is the stencil shape which is found on the SMask and effectively cutout from the solid image by the SMask. So the you need to build the image from the 2 separate datastreams.

What makes it complicated is that there is a actually no need for this complexity – the image data could jut have been added as the original image data (it just needs inverting). In fact that is how we handle these cases in our Java PDF viewer, spotting the blank image and using the SMask data reversed.

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 “Interesting PDF bugs – using SMask and image ‘the opposite way’ round

  1. Ah, so I’m not the only one scratching my head over these types of images. I had to deal with them a while ago when developing an image editor for PDF files.

    I appreciate that you post these articles about the guts of the PDF system.

    Thanks.

  2. You are definitely not the only one scratching (I seem to have lost lots of hair)!

    It is an over-engineered way to build a image and it makes it far more complex than it needs to be (it’s not as if using the SMask actually adds anything to it).

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>