Fine tuning PDF image color with ICC profiles

Colour can be a complicated topic in PDF because not only can you have lots of different types of color in PDF (Lab, RGB, CMYK, etc), but you can even have different types of RGB and CMYK. This article is part explanation of how color can work in a PDF file and part tutorial on some tweaks you can use to improve display. Thank-you to Random House USA for permission to use their file.

Color can generally be defined using an ICC colorspace file. This is a standard format devised by the ICC who have a website at the appropriately named site http://www.color.org/. If you are seriously interested in Color, they have lots of resources.

In Java you can load an ICC colorspace very easily with the code. This code example shows how you could setup a Colorspace using an ICC example. ICC colorspaces can match different types of Colorspace (so they are either compatible with CMYK or RGB or GRAY or Lab – you cannot create an RGB colorspace with a CMYK ICC profile). You can also use a Color profile( ends .pf) to create a Colorspace with the same code.

String profile="path to RGB icc file";
ColorSpace rgbCS=null;
if(profile!=null)
   rgbCS=new ICC_ColorSpace(ICC_Profile.getInstance(new
                              FileInputStream(profile));
else
   rgbCS=ColorSpace.getInstance(ColorSpace.CS_sRGB);

Now let us have a look at an example file…

Here is a PDF page in Adobe Acrobat 9.0

This page contains a single image which is encoded using a variation on a CYMK colorspace called a YCCK colorspace.

This is where Color gets complicated because there are different ways to convert YCCK to CMYK – a fast approximate formula and a more accurate, slower way using a YCC color profile and a CMY color profile (K is unchanged so does not need translation). By default we us the fast approximate way in our Java PDF viewer. Here is the same page.

 

Not bad but the colors are a little brighter than in the original. So lets use a profile conversion (in our PDF viewer we have a JVM option to set the 2 profiles needed for the conversion (-Dorg.jpedal.useICC=”YCC=/Users/markee/colorprofiles/YCC601.pf, CMY=/Users/markee/colorprofiles/CMY.pf” ).

It is closer but still clear differences. This is because we convert images into sRGB in Java (and there are different versions of RGB). It turns out Adobe is using a variation of RGB and a close match is CIERGB (the icc file is available to download from their site). So let us use CIERGB instead or sRGB. In our viewer we set the flag -Dorg.jpedal.RGBprofile=/Users/markee/Downloads/CIERGB.icc

That looks better! Let’s see a montage of sRGB (left), Adobe (middle), and CIERGB (right).

So there you are – lots of really nice screenshots showing what differences you can get in colors by using different techniques/profiles. What profiles do you recommend?

This post is part of our “Understanding the PDF File Format” series. In each article, we discuss a PDF feature, bug, gotcha or tip. 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>