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.

Understanding the PDF file format – the color white 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 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!

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

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.

Enabling SVG Gzip Compression on Apache and NGINX

Gzip compression is a widely supported method of reducing the size of the content sent from a web server in order to improve the...
Leon Atherton
47 sec read

Leave a Reply

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

IDRsolutions Ltd 2019. All rights reserved.