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).
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!
Are you a Developer working with PDF files?
Our developers guide contains a large number of technical posts to help you understand the PDF file Format.
Find out more about our software for Developers
|Convert PDF to HTML5 or SVG|
|Convert AcroForms and XFA to HTML5|
|Java PDF SDK for working with PDF files|