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 – Color

1 min read

Color is a complex topic in PDF. This article helps to explain how it works.

Color in PDF files

Color can be defined in different ways in a PDF. This is because the PDF file specification is a very flexible format with lots of uses. Different tasks have come up with different ways to talk about colours. A way of defining colors is called a Colorspace.

Televisions and computers use 3 ‘base’ colours generated by a Red, a Green and a Blue cathode. The output of these would be mixed together in different amounts to give all the colors you see on the television screen (the RGB colorspace).

A printer would usually print using a combination of 4 inks (Cyan, Magenta, Yellow and Key, which is really black) to produce color prints. Or they might use a selection of known inks and print them one at a time (Separation colorspaces).

Because PDFs are used in digital, print and lots of other environments, the PDF specification allows you to choose the most appropriate and natural way to think about color for that process. When a PDF is displayed the software has to work out how to convert the color into an appropriate form (for example a print PDF using CMYK needs to be displayed on an RGB computer screen).

Color conversion

Converting between colors is not always a straight-forward task. For some conversions, there is a simple Maths formula while for others there are complex translation tables called profiles. Even with a formula, there are different versions available which give different results. There are also fast and approximate methods versus more accurate and slow methods. All PDF tools have to choose the methods which offer the best compromise for their requirements. Xpdf, for example, usually uses a formula to handle CMYK, which is why some shades of black or white can look different compared with Adobe Acrobat, which uses a profile.


The most accurate way to convert between colors is to use a profile. When I wrote the color handling code for our Java PDF viewer, I needed to convert all the colors in a PDF file into sRGB so that I could use them in Java. Wherever possible, I used profiles to give the closest match to what Adobe Acrobat does.

More help on color conversions

If you need to understand color and color versions in more detail, I have found the best source of information is wikipedia. Good luck and let us know if you come across any interesting tips…

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!

Did you know...

IDRsolutions offers a whole range of online file converters to convert PDF and Microsoft Excel, Word and Office Documents to HTML5, SVG or image formats?

It is free to use for single file conversions and also includes Developer links if you want to use our commercial software for bulk conversions. Find out more on this page

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 2020. All rights reserved.