Interesting PDF bugs – PDF text is really a tiny image with a big smask

Today’s article is a variation on an old favourite I have written about before. I have been investigating a PDF file which did not display correctly some text in our Java PDF viewer…

So I opened up the PDF file (which claimed to be created by Microsoft Publisher 2010) and found the raw commands relating to the text. It turned out that it was not actually text but a tiny 2×2 pixel dot applied to a much larger SMask.

Most of the time, an Smask is used to add a clip to an image. But the trick in this case was to actually have the inverted image on the stencil and then draw it onto a solid image. It is a slightly ‘odd’ way to do things but it is not disallowed in the PDF spec so we need to handle it correctly without slowing down or breaking the generic code to handle the more usual way to apply an SMask.

Our generic code did not allow for this case. The fix is to spot this usage case and substitute a new image the same size as the stencil before applying it.

This fixes this ‘pdf bug’ nicely. But it is a reminder that you can never take anything for granted in PDF files if you want to avoid ‘pdf bugs’.

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.

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>