Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

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

49 sec read

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 just 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!

Did you know...

IDRsolutions offers a whole range of online file converters to convert PDF and Microsoft Excel, Word and Office Documents to HTML5, SVG or image formats?

It is free to use for single file conversions and also includes Developer links if you want to use our commercial software for bulk conversions. Find out more on this page

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

How to read HEIC image files in Java with…

In this article, I will explain how to read HEIC files into Java as a BufferedImage. ImageIO does not read HEIC file types so...
Mark Stephens
1 min read

How to convert WMF files to SVG in java…

This article will show you how to convert WMF files into SVG files using our JDeli Java Image library. What is WMF? WMF is...
Amy Pearson
1 min read

How to write WebP images in Java

In this article, I will walk you through how to write out images as WebP images in Java. ImageIO does not support WebP images...
Mark Stephens
1 min read

6 Replies to “Interesting PDF bugs – using SMask and image ‘the…”

  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.


  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).

  3. Happy to report (not really, lol) that 8 years after your post this issue is still alive and well. I was happy to find this as it is exactly the situation I’m trying to accommodate with our PDF viewer application. I’m very new to PDF development though and was hoping you might consider doing a follow up article with just a little more detail as to how you programmed the PDF viewer to handle this situation. Specifically, what about the PDF object indicates to you that it is a blank image and how do you reverse the SMask data?

  4. Do you mean that the complex part it finding out if it is in fact a blank image? Would love to explore the idea of just using one of your viewers. Unfortunately, it’s for a Windows Forms application and I was under the impression that yours were all Java. Is that not the case?

    Thanks for the reply!

    1. The JPedal viewer is Java but that does stop people using it on Windows either to call or to rasterize the pages as images. We also have BuildVu which converts the pages to HTML5 to display in a browser and integrate into other apps as HTML5.

Leave a Reply

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

IDRsolutions Ltd 2020. All rights reserved.