Today’s PDF file was not so much of a bug as more a ‘how can we emulate this in Java issue’…
I was sent a PDF file which did not correctly display in JPedal. It had a big rectangular block of color on it. In Java you can have a clip on the page which prevents parts of the page being drawn onto (it is like a stencil covering part of the page so you cannot paint there). The clip is Java is fairly flexible – it can be any shape. However it cannot be an image…
The PDF file format has a concept of an SMask which is essentially a bit-mapped clip. So how can we emulate this feature in Java?
There are several possible solutions. The way we have used is to detect this scenario and instead of filling the rectangle we create an image based on the SMask. Because it is an image we can scan all the pixels and see which are opaque (and make them transparent) and which should let the colour through (and set them to the correct colour). It needs more memory but it provides the flexibilty needed to emulate this feature in most PDF files. And it is the solution the javafx team have used to solve a very similar problem…
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!
Are you a Developer working with PDF files?
Our developers guide contains a large number of technical posts to help you understand the PDF file Format.
Find out more about our software for Developers
|
|
|