Understanding the PDF file format – the color white in PDF files

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 set in the GraphicsState. 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.

This post is part of our “Understanding the PDF File Format” series. In each article, we aim to take a specific PDF feature and explain it in simple terms. 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!

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>