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)
- How we are improving our code quality with IDEA in 2018 - March 7, 2018
- How we are improving our code quality with NetBeans in 2018 - March 1, 2018
- 3 ways that the European Union is changing the way Companies write software in 2018 - January 31, 2018
- IDRsolutions product range update for 2018 - January 22, 2018
- 4 ways Companies can make remote working successful - December 21, 2017