3.3 Working with Color 57
3.3 Working with Color
3.3.1 Color and Color Spaces
PDFlib clients may specify the colors used for filling and stroking the interior of paths
and text characters. Colors may be specified in several color spaces:
> Gray values between 0=black and 1=white;
> RGB triples, i.e., three values between 0 and 1 specifying the percentage of red, green,
and blue; (0, 0, 0)=black, (1, 1, 1)=white;
> Four CMYK values between 0=no color and 1=full color, representing cyan, magenta,
yellow, and black values; (0, 0, 0, 0)=white, (0, 0, 0, 1)=black. Note that this is different
from the RGB specification.
> Device-independent colors in the CIE L*a*b* color space are specified by a luminance
value and two color values (see Section 3.3.6, »Device-Independent CIE L*a*b* Color«,
> ICC-based colors are specified with the help of an ICC profile (see Section 3.3.4, »Color
Management and ICC Profiles«, page 60).
> Spot color (separation color space): a predefined or arbitrarily named custom color
with an alternate representation in one of the other color spaces above; this is gener-
ally used for preparing documents which are intended to be printed on an offset
printing machine with one or more custom colors. The tint value (percentage) rang-
es from 0=no color to 1=maximum intensity of the spot color. See Section 3.3.3, »Spot
Colors«, page 58, for a list of spot color names.
> Patterns: tiling with an object composed of arbitrary text, vector, or image graphics
(see Section 3.3.2, »Patterns and Smooth Shadings«, page 57).
> Shadings (smooth blends) provide a gradual transition between two colors, and are
based on another color space (see Section 3.3.2, »Patterns and Smooth Shadings«,
> The indexed color space is a not really a color space on its own, but rather an efficient
coding of another color space. It will automatically be generated when an indexed
(palette-based) image is imported.
The default color for stroke and fill operations is black.
3.3.2 Patterns and Smooth Shadings
As an alternative to solid colors, patterns and shadings are special kinds of colors which
can be used to fill or stroke arbitrary objects.
Patterns. A pattern is defined by an arbitrary number of painting operations which
are grouped into a single entity. This group of objects can be used to fill or stroke arbi-
trary other objects by replicating (or tiling) the group over the entire area to be filled or
the path to be stroked. Working with patterns involves the following steps:
> First, the pattern must be defined between PDF_begin_pattern( ) and PDF_end_
pattern( ). Most graphics operators can be used to define a pattern.
> The pattern handle returned by PDF_begin_pattern( ) can be used to set the pattern as
the current color using PDF_setcolor( ).
Depending on the painttype parameter of PDF_begin_pattern( ) the pattern definition
may or may not include its own color specification. If painttype is 1, the pattern defini-
Chapter 3: PDFlib Programming
tion must contain its own color specification and will always look the same; if painttype
is 2, the pattern definition must not include any color specification. Instead, the current
fill or stroke color will be applied when the pattern is used for filling or stroking.
Note Patterns can also be defined based on a smooth shading (see below).
Smooth shadings. Smooth shadings, also called color blends or gradients, provide a
continuous transition from one color to another. Both colors must be specified in the
same color space. PDFlib supports two different kinds of geometry for smooth shadings:
> axial shadings are defined along a line;
> radial shadings are defined between two circles.
Shadings are defined as a transition between two colors. The first color is always taken
to be the current fill color; the second color is provided in the c1, c2, c3, and c4 parameters
of PDF_shading( ). These numerical values will be interpreted in the first color’s color
space according to the description of PDF_setcolor( ).
Calling PDF_shading( ) will return a handle to a shading object which can be used in
> Fill an area with PDF_shfill( ). This method can be used when the geometry of the ob-
ject to be filled is the same as the geometry of the shading. Contrary to its name this
function will not only fill the interior of the object, but also affects the exterior. This
behavior can be modified with PDF_clip( ).
> Define a shading pattern to be used for filling more complex objects. This involves
calling PDF_shading_pattern( ) to create a pattern based on the shading, and using this
pattern to fill or stroke arbitrary objects.
3.3.3 Spot Colors
PDFlib supports spot colors (technically known as Separation color space in PDF, al-
though the term separation is generally used with process colors, too) which can be
used to print custom colors outside the range of colors mixed from process colors. Spot
colors are specified by name, and in PDF are always accompanied by an alternate color
which closely, but not exactly, resembles the spot color. Acrobat will use the alternate
color for screen display and printing to devices which do not support spot colors (such
as office printers). On the printing press the requested spot color will be applied in addi-
tion to any process colors which may be used in the document. This requires the PDF
files to be post-processed by a process called color separation.
Note PDF color separation is outside the scope of PDFlib; additional software for Acrobat 5, such as
the plugins callas pdfOutput PRO
, Lantana Crackerjack
, or in-RIP separation is required.
Note Some spot colors do not display correctly on screen in Acrobat 5 when Overprint Preview is
turned on. They can be separated and printed correctly, though.
PDFlib supports various built-in spot color libraries as well as custom (user-defined)
spot colors. When a spot color name is requested with PDF_makespotcolor( ) PDFlib will
first check whether the requested spot color can be found in one of its built-in libraries.
If so, PDFlib will use built-in values for the alternate color. Otherwise the spot color is as-
sumed to be a user-defined color, and the client must supply appropriate alternate col-
1. See http://www.callassoftware.com
2. See http://www.lantanarips.com
3.3 Working with Color 59
or values (via the current color). Built-in spot colors can not be redefined with custom
alternate values. Spot colors can be tinted, i.e., they can be used with a percentage be-
tween 0 and 1.
PDFlib will automatically generate suitable alternate colors for built-in spot colors
when a PDF/X conformance level has been selected (see Section 3.4, »PDF/X Support«,
page 64). For custom spot colors it is the user’s responsibility to provide alternate colors
which are compatible with the selected PDF/X conformance level.
Note Built-in spot color data and the corresponding trademarks have been licensed by PDFlib GmbH
from the respective trademark owners for use in PDFlib software.
PANTONE® colors. PANTONE Colors are well-known and
widely used on a world-wide basis. PDFlib fully supports the
PANTONE MATCHING SYSTEM®, totalling ca. 20000 swatches.
All color swatch names from the following digital color li-
braries can be used (sample swatch names are provided in
> PANTONE solid coated d (PANTONE 185 C)
> PANTONE solid uncoated d (PANTONE 185 U)
> PANTONE solid matte e (PANTONE 185 M)
> PANTONE process coated d (PANTONE DS 35-1 C)
> PANTONE process uncoated d (PANTONE DS 35-1 U)
> PANTONE process coated EURO O (PANTONE DE 35-1 C)
> PANTONE pastel coated d (PANTONE 9461 C)
> PANTONE pastel uncoated d (PANTONE 9461 U)
> PANTONE metallic coated d (PANTONE 871 C)
> PANTONE solid to process coated d (PANTONE 185 PC)
> PANTONE solid to process coated EURO O (PANTONE 185 EC)
> PANTONE hexachrome® coated d (PANTONE H 305-1 C)
> PANTONE hexachrome® uncoated d (PANTONE H 305-1 U)
> PANTONE solid in hexachrome coated d (PANTONE 185 HC)
Old color name prefixes CV, CVV, CVU, CVC, and CVP will also be accepted. The PANTONE
prefix must always be provided in the swatch name as shown in the examples. General-
ly, PANTONE Color names must be constructed according to the following scheme:
PANTONE <id> <paperstock>
where <id> is the identifier of the color (e.g., 185) and <paperstock> the abbreviation of the
paper stock in use (e.g., C for coated). A single space character must be provided between
all components constituting the swatch name. It is an error to request a spot color name
starting with the PANTONE prefix if the name does not represent a valid PANTONE Color.
The following code snippet demonstrates the use of a PANTONE Color with a tint value
of 70 percent:
spot = PDF_makespotcolor(p, "PANTONE 281 U", 0);
PDF_setcolor(p, "fill", "spot", spot, 0.7, 0, 0);
Note PANTONE® Colors displayed here may not match PANTONE-identified standards. Consult cur-
rent PANTONE Color Publications for accurate color. PANTONE® and other Pantone, Inc. trade-
marks are the property of Pantone, Inc. © Pantone, Inc., 2003.
Chapter 3: PDFlib Programming
Note PANTONE® Colors are currently not supported in the PDF/X-1 and PDF/X-1a modes.
HKS® colors. . The HKS color system is widely used in Germa-
ny and other European countries. PDFlib fully supports HKS
colors, including those from the new HKS 3000 plus palettes.
All color swatch names from the following digital color librar-
ies (Farbfächer) can be used (sample swatch names are provid-
ed in parentheses):
> HKS K (Kunstdruckpapier) for gloss art paper, 88 colors (HKS 43 K)
> HKS N (Naturpapier) for natural paper, 88 colors (HKS 43 N)
> HKS E (Endlospapier) for continuous stationary/coated, 90 colors (HKS 43 E)
> HKS Ek (Endlospapier) for continuous stationary/uncoated, 88 colors (HKS 43 E)
> HKS En: identical to HKS E (HKS 43 En)
> HKS Z (Zeitungspapier) for newsprint, 50 colors (HKS 43 Z)
The HKS prefix must always be provided in the swatch name as shown in the examples.
Generally, HKS color names must be constructed according to one of the following
HKS <id> <paperstock>
where <id> is the identifier of the color (e.g., 43) and <paperstock> the abbreviation of the
paper stock in use (e.g., N for natural paper). A single space character must be provided
between the HKS, <id>, and <paperstock> components constituting the swatch name. It is
an error to request a spot color name starting with the HKS prefix if the name does not
represent a valid HKS color. The following code snippet demonstrates the use of an HKS
color with a tint value of 70 percent:
spot = PDF_makespotcolor(p, "HKS 38 E", 0);
PDF_setcolor(p, "fill", "spot", spot, 0.7, 0, 0);
User-defined spot colors. In addition to built-in spot colors as detailed above, PDFlib
supports custom spot colors. These can be assigned an arbitrary name (which must not
conflict with the name of any built-in color, however) and an alternate color which will
be used for screen preview or low-quality printing, but not for high-quality color sepa-
rations. The client is responsible for providing suitable alternate colors for custom spot
There is no separate PDFlib function for setting the alternate color for a new spot col-
or; instead, the current fill color will be used. Except for an additional call to set the al-
ternate color, defining and using custom spot colors works similarly to using built-in
PDF_setcolor(p, "fill", "cmyk", 0.2, 1.0, 0.2, 0); /* define alternate CMYK values */
spot = PDF_makespotcolor(p, "CompanyLogo", 0);
/* derive a spot color from it */
PDF_setcolor(p, "fill", "spot", spot, 1, 0, 0);
/* set the spot color */
3.3.4 Color Management and ICC Profiles
The International Color Consortium (ICC)
defined a file format for specifying color
characteristics of input and output devices. These ICC color profiles are considered an
industry standard, and are supported by all major color management system and appli-
1. See http://www.color.org
Documents you may be interested
Documents you may be interested