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!
Latest posts by Mark Stephens (see all)
- 4 ways Companies can make remote working successful - December 21, 2017
- My experience of a Turkish bath (visiting Istanbul for DevFest) - November 24, 2017
- My 5 key takeaways from JavaOne 2017 - October 6, 2017
- My notes and pictures from thursday JavaOne 2017 - October 5, 2017
- My notes and pictures from Wednesday JavaOne 2017 - October 5, 2017