Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Do you need to process or display PDF files?

Find out why you should be using IDRSolutions software

Why is white a special color in PDF files?

1 min read

The color white has been on my mind a lot recently…

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.

Investigating the color white

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.



Our software libraries allow you to

Convert PDF files to HTML
Use PDF Forms in a web browser
Convert PDF Documents to an image
Work with PDF Documents in Java
Read and write HEIC and other Image formats in Java
Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

How to insert an image into a PDF

Recently, we released JPedal 2023.07 which contains the ability to insert images into PDF files. All you need is a copy of JPedal, a...
Jacob Collins
18 sec read