White is a special color in the PDF file format. This is because of the way different colours work in the PDF file format. If you use color to paint over an existing color, 3 things could happen.
1. The color overwrites If you draw a green box over a red background, then the covered red bit is replaced by a green box.
2. The colors mix As happens with paints in real life, the colors mix so if you draw a white box over a red background you get a pink box where the red and white mix together.
3. The new color is transparent You draw an image and the background is regarded as transparent and shows that is behind the image.
Because the PDF file format tries to support different types of color, it allows all options to happen. In particular CMYK mode allows white to be treated as a transparent color – it is a setting in the GraphicsState object. This allows PDF files to mimic qualities of ink rather than just draw over.
This is complicated enough to implement but working with Java adds two additional problems.
First of all, different types of BufferedImage exist in Java and they define white in different ways. The JPEG decoders will return a different type of image compared to building the image yourself. So, sometimes it is color zero, while other times it is value 255,255,255
Secondly, Java works in sRGB so data needs to be converted into that format from ICC or CMYK. When the color is defined with its own Key (Black) element, it is much easier to implement transparency on white rather than after it is converted to sRGB. And also Java does not always convert white to 255,255,255.
So white is a very important and complicated color and one of the many areas of the PDF file when things are not always as they first seem, especially manipulating them in Java.
Do you need to solve any of these problems?
|Display PDF documents in a Web app|
|Use PDF Forms in a web browser|
|Convert PDF Documents to an image|
|Work with PDF Documents in Java|
Are you a Developer working with PDF files?
|Learn more about PDF file format|