The 11 color space families of PDF: how each is written, how many components its colors have, and the color it starts with.
The graphics state holds a current color space and a current color, one pair for stroking and one for nonstroking operations such as fills. A color is a list of numbers, read according to the space. A space that takes no parameters is written as its bare name, like /DeviceRGB. Any other is an array whose first element names the family, like [/ICCBased 6 0 R]. A version badge marks a family or entry added after PDF 1.0. For how color fits into a page, see Content streams in Learning.
Families
| Family | Written as | Components | Initial color |
|---|---|---|---|
| DeviceColors as the output device makes them: light on a screen, ink on paper. They take no parameters, so each family is one space, written as a bare name. | |||
DeviceGray | /DeviceGray, or /G in an inline image | 1: gray, from 0.0 (black) to 1.0 (white) | 0, black |
DeviceRGB | /DeviceRGB, or /RGB in an inline image | 3: red, green and blue light, each 0.0 to 1.0 (full intensity) | 0 0 0, black |
DeviceCMYK | /DeviceCMYK, or /CMYK in an inline image | 4: cyan, magenta, yellow and black ink, each 0.0 to 1.0 (full ink) | 0 0 0 1, black |
| CIE-basedDevice-independent colors, tied to the CIE 1931 XYZ space by a dictionary of parameters or by an ICC profile. | |||
CalGray | [/CalGray dict], with WhitePoint, BlackPoint and Gamma | 1: A, a calibrated gray, 0.0 to 1.0 | 0 |
CalRGB | [/CalRGB dict], with WhitePoint, BlackPoint, Gamma and Matrix | 3: A, B and C, a calibrated red, green and blue, each 0.0 to 1.0 | 0 0 0 |
Lab | [/Lab dict], with WhitePoint, BlackPoint and Range | 3: L* from 0 to 100, then a* and b* within Range, by default −100 to 100 | 0 0 0, or the nearest value inside Range if it excludes 0 |
ICCBased | [/ICCBased stream], where the stream is an ICC profile with N, Alternate, Range and Metadata | N: 1, 3 or 4, each within Range, by default 0.0 to 1.0 | All 0, or the nearest value inside Range if it excludes 0 |
| SpecialFeatures built on top of another space: patterns, color tables, and individual inks such as spot colors. | |||
Indexed | [/Indexed base hival lookup], or /I for the name in an inline image. See the elements. | 1: an index into the color table, an integer from 0 to hival (at most 255) | 0, the first color in the table |
Pattern | /Pattern, or [/Pattern underlying] for uncolored tiling patterns | None: the “color” is the name of a /Pattern resource. An uncolored tiling pattern also takes the components of the underlying space. | A pattern that paints nothing |
Separation | [/Separation name alternateSpace tintTransform]. See the elements. | 1: a tint of the colorant, from 0.0 (none) to 1.0 (full) | 1, full tint |
DeviceN | [/DeviceN names alternateSpace tintTransform], optionally followed by an attributes dictionary | One tint per colorant in names, each 0.0 to 1.0 | 1 for every component |
The specs mark the device families and Indexed PDF 1.1, the version that added CS and cs. They are older than that: PDF 1.0 already had G, RG, K and their lower-case forms, and its images could use DeviceGray, DeviceRGB, DeviceCMYK and Indexed.
Parameters
The device families have no parameters. The CIE-based families take a dictionary or, for ICCBased, a stream. The special families take array elements, some of which are color spaces themselves.
CalGray, CalRGB and Lab dictionaries
The second element of the array is a dictionary. These are all the entries the three families use:
| Key | Meaning |
|---|---|
WhitePointCalGray, CalRGB, Lab · required | The diffuse white point, as CIE 1931 XYZ tristimulus values [XW YW ZW]. X and Z must be positive and Y must be 1.0. D65 daylight, which the spec examples use, is [0.9505 1.0 1.0890]. |
BlackPointCalGray, CalRGB, Lab | The diffuse black point [XB YB ZB], none of them negative. Default [0 0 0]. |
GammaCalGray | One positive number, usually 1 or more. Default 1. |
GammaCalRGB | Three numbers, one for each component. Default [1 1 1]. |
MatrixCalRGB | Nine numbers [XA YA ZA XB … ZC] that turn the gamma-decoded components into XYZ. Default the identity, [1 0 0 0 1 0 0 0 1]. |
RangeLab | Four numbers [amin amax bmin bmax] bounding a* and b*. Values outside are clipped without an error. Default [-100 100 -100 100]. |
CalGray turns its one component into XYZ by raising it to the gamma and scaling the white point: X = XW × AG, and the same for Y and Z. CalRGB raises each component to its own gamma, then multiplies by Matrix. Lab uses the fixed CIE 1976 L*a*b* formulas with its white point.
PDF 1.1 also partly defined a CalCMYK family that was never finished. ISO 32000-1 calls it deprecated, ISO 32000-2 says it has been removed, and readers treat it as DeviceCMYK. Calibrated CMYK is written as an ICCBased space.
ICC profile streams
The second element of the array is a stream whose data is an ICC profile. Besides the entries every stream has, such as /Length and /Filter, its dictionary has:
| Key | Meaning |
|---|---|
Nrequired | The number of components: 1, 3 or 4. It must match the profile. |
Alternate | A space to use if the reader can’t use the profile: any space with N components except Pattern. Color values are passed to it unchanged, without conversion. Default DeviceGray, DeviceRGB or DeviceCMYK, by N. |
Range | 2 × N numbers [min0 max0 min1 max1 …], which must match the profile. Default [0 1 0 1 …]. In a Lab profile, L* runs from 0 to 100 and a* and b* from −128 to 127. |
Metadata | A metadata stream describing the profile. |
The profile’s device class must be input (scnr), display (mntr), output (prtr) or color space (spac), and its data Gray, RGB, CMYK or Lab. The ICC version a reader must support follows the PDF version: ICC 3.3 for PDF 1.3, ICC.1:1998-09 for 1.4, ICC.1:2004-10 for 1.7 and ICC.1:2010 for 2.0. Only the profile’s direction toward CIE (AToB) is used, and its rendering intent is ignored: PDF sets that with ri or an image’s /Intent.
sRGB, the usual space for screen colors, can be written exactly only as an ICCBased space. A CalRGB space can approximate it.
Indexed, Pattern, Separation and DeviceN arrays
The special families take their parameters as array elements, in this order:
| Element | Meaning |
|---|---|
| baseIndexed | The space the table’s colors are in: any device or CIE-based space, or (PDF 1.3) a Separation or DeviceN space. Not Pattern or another Indexed space. |
| hivalIndexed | The highest valid index, at most 255. The table has hival + 1 colors. |
| lookupIndexed | The color table: a stream, or (PDF 1.2) a string, of m × (hival + 1) bytes, where m is the number of components in base. Each byte maps 0–255 onto that component’s range, so <FF0000> in DeviceRGB is red. |
| underlyingPattern | Only for an uncolored tiling pattern (/PaintType 2), whose content stream sets no colors: the space its color is given in, as components before the pattern name in scn. Any space except Pattern. |
| nameSeparation | The colorant (ink), such as /Gold, or one of the special names /All and /None. |
| namesDeviceN | An array of colorant names, one per component. They must all differ, except that /None may repeat. /All isn’t allowed. |
| alternateSpaceSeparation, DeviceN | Where to paint when the device doesn’t have the colorants: any device or CIE-based space, but not a special one. |
| tintTransformSeparation, DeviceN | A function from the tint values to the components of alternateSpace. |
| attributesDeviceN | Optional: a dictionary describing the colorants, below. |
Tints work like ink, as in CMYK: 0.0 is none of the colorant and 1.0 the most, even on a device that makes the color with light. When the device has a Separation’s colorant, the reader paints the tints with it and ignores the alternate space. A DeviceN space uses its colorants only if the device has all of them. On a display, a Separation space always paints through its alternate space. Painting in the alternate space looks right for opaque objects but not under overprinting or transparency.
How many DeviceN components a reader handles is an implementation limit: 8 in the PDF 1.4 reference (Appendix C), 32 in ISO 32000-1 (Annex C).
Spot colors
Separation and DeviceN spaces name colorants: process inks like /Cyan, or spot inks such as a brand color, a metallic or a varnish. When the device has every colorant named, it applies the tints directly. Otherwise the reader runs the tint transform and paints in the alternate space.
All and None
| Name | Meaning |
|---|---|
/All | Every colorant the device has, process colorants included, at once. Used for marks that must appear on every separation, such as registration targets, usually painted last. Separation only: a DeviceN space can’t use it. |
/None | Paints nothing. In a DeviceN space, a /None component is dropped when the device paints the colorants directly, but still passed to the tint transform when the alternate space is used. A DeviceN space whose names are all /None never paints and never uses its alternate space. |
Every reader supports /All and /None, even on a device with no other colorants. With either name a Separation space ignores its alternate space and tint transform, but the array must still hold valid ones.
DeviceN attributes and NChannel
The optional fifth element of a DeviceN array is a dictionary about its colorants. In PDF 1.4 it has one entry, Colorants, and doesn’t change how the space paints. /NChannel subtype and the entries that go with it.
| Key | Meaning |
|---|---|
Subtype | /DeviceN (the default) or /NChannel. |
Colorants | A dictionary from colorant names to Separation space arrays, describing each colorant alone; the DeviceN space’s own alternate describes them only in combination. It may list colorants the space doesn’t use. Required in an NChannel space that has spot colorants, and must then cover all of them. |
Process | Required in an NChannel space that has process components: ColorSpace, the process space (any device or CIE-based space), and Components, the names its components have in names, in order. |
MixingHints | Hints for mixing the inks without the tint transform: Solidities (how opaque each ink is, 0.0 to 1.0), PrintingOrder (the order the inks go down, required with Solidities) and DotGain (a function per ink). |
An NChannel space describes each component, so the reader can handle them one by one: real inks where the device has them, the alternate space only for the rest. Its process components come from a single process space and, if that space is additive like RGB, take their natural values (1.0 is full intensity) instead of tints. /None isn’t allowed. A reader older than PDF 1.6 sees a plain DeviceN space, which is why alternateSpace and tintTransform are still required.
Setting colors
Upper case sets the stroking color, lower case the nonstroking color. Both start as black in DeviceGray. Color operators can appear between graphics objects and inside text objects.
| Operators | Operands | What they do |
|---|---|---|
CScs | name | Select a color space, and reset the color to that space’s initial value. The operand is /DeviceGray, /DeviceRGB, /DeviceCMYK, /Pattern, or a name in the /ColorSpace resources. Those four names always mean the space itself, never a resource. |
SCsc | c1 … cn | Set the color in a device, CalGray, CalRGB, Lab or Indexed space: one, three or four numbers. |
SCNscn | c1 … cn [name] | Set the color in any space, and the only way to set one in ICCBased, Separation, DeviceN and Pattern spaces. In a Pattern space, name is a /Pattern resource, with components before it only for an uncolored tiling pattern. |
Gg | gray | Select DeviceGray and set the gray level, in one step. |
RGrg | r g b | Select DeviceRGB and set the color. |
Kk | c m y k | Select DeviceCMYK and set the color. |
G,RGandKand their lower-case forms select the default color space instead, if the resources define one.- In an Indexed space, an index that isn’t an integer is rounded, and one outside 0 to hival is moved to the nearest end.
- A Type 3 glyph that starts with
d1, and an uncolored tiling pattern, take their color from outside, so inside them the color operators,ri,shand images other than image masks aren’t allowed.
Where color spaces appear
| Where | How |
|---|---|
The /ColorSpace resources | A subdictionary of a resource dictionary that maps names to color spaces, for example /CS0 [/ICCBased 6 0 R]. CS and cs take only a name, so any space that needs an array must be defined here: a content stream can’t contain a color space array. |
An image XObject’s /ColorSpace | The name or array itself, not a resource name. Any space except Pattern. Required, except for image masks, which can’t have one, and JPXDecode images (PDF 1.5), which can take theirs from the JPEG 2000 data. |
An inline image’s /CS | A device space, by its full name or by /G, /RGB or /CMYK, or an Indexed space with a device base and a string table, where /I abbreviates Indexed. From PDF 1.2 it can also be a name in the /ColorSpace resources, for any space an image XObject could use. The abbreviations work only in inline images. |
| Inside another color space | The base of an Indexed space, the alternate of a Separation, DeviceN or ICCBased space, and the underlying space of a Pattern space are written out directly, as a name or array, never as a resource name. |
| Elsewhere | Shading dictionaries have a /ColorSpace (any space except Pattern), and transparency groups a /CS, the space they blend in. |
An inline image can carry a small Indexed space of its own, with the abbreviations:
q 200 0 0 50 72 600 cm % stretch the 4×1 image to 200×50 BI /W 4 /H 1 /BPC 1 /F /AHx /CS [/I /RGB 1 <FF0000 0000FF>] % Indexed on DeviceRGB: 0 is red, 1 is blue ID 50> EI % index bits 0101: red, blue, red, blue Q
Default color spaces
A file can make its device colors device-independent without touching its content streams. If the current resources’ /ColorSpace dictionary has an entry named DefaultGray, DefaultRGB or DefaultCMYK, the reader uses that space whenever DeviceGray, DeviceRGB or DeviceCMYK is selected: by CS or cs, by G, RG or K, or by an image, inline image or shading.
/Resources << /ColorSpace << /DefaultRGB [/ICCBased 6 0 R] >> >>
1 0 0 rg 72 72 100 100 re f % red as the ICC profile defines it, not as the device does
- The color values are passed on unchanged, so the default space needs the same number of components, compatible ranges, and the same additive or subtractive sense. Values outside its ranges are moved to the nearest valid value.
- It can be any space except Lab, Indexed or Pattern.
- It also replaces a device space used inside a special space: the base of an Indexed space, the underlying space of a Pattern space, and the alternate of a Separation or DeviceN space when the alternate is actually used.
DefaultGray and DefaultRGB. DefaultCMYK first appears in the PDF 1.3 reference.
Example
A page with two color spaces in its resources, an ICC-calibrated RGB and a spot ink named Gold:
3 0 obj
<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792]
/Resources << /ColorSpace << /CS0 [/ICCBased 6 0 R]
/CS1 [/Separation /Gold /DeviceCMYK 7 0 R] >> >>
/Contents 4 0 R >>
endobj
6 0 obj % the ICC profile
<< /N 3 /Alternate /DeviceRGB /Filter /FlateDecode /Length 2615 >>
stream
…compressed profile data…
endstream
endobj
7 0 obj % tint transform: tint → CMYK
<< /FunctionType 2 /Domain [0 1] /C0 [0 0 0 0] /C1 [0 0.15 0.65 0.1] /N 1 >>
endobjThe content stream picks each space by its resource name:
/CS0 cs 0.1 0.3 0.7 scn % ICCBased takes scn, not sc 72 600 200 100 re f /CS1 cs 0.5 scn % a 50% tint of the Gold ink 72 450 200 100 re f /DeviceGray CS 0.5 SC 4 w % the same as 0.5 G 72 400 m 272 400 l S
On a press with a Gold plate, the second rectangle prints as a half tint of gold ink. Anywhere else the reader evaluates function 7 at 0.5, which interpolates between C0 and C1 to give CMYK 0 0.075 0.325 0.05, and paints that.
What PDF 2.0 changed
ISO 32000-2 lists the same eleven families and the same operators. The changes are in the details:
- Readers must support ICC.1:2010 (ISO 15076-1:2010) profiles. An ICCBased space’s
Alternateis now only for a profile of a newer ICC version than the reader can process; otherwise readers should not use it. CalCMYK, deprecated in ISO 32000-1, is described as removed. Readers still treat it as DeviceCMYK.- A color remapped through
DefaultGray,DefaultRGBorDefaultCMYKis no longer subject to the rules that apply only to device color spaces. - Color operators inside a
d1glyph or an uncolored tiling pattern are ignored. Earlier specs called them an error in one place and ignored them in another. - An Indexed index exactly halfway between two integers rounds up.
PDF 2.0 A new graphics state entry,UseBlackPtComp, set to/ON,/OFFor/Defaultthroughgs, controls black point compensation when CIE-based colors are converted.
Checked against §4.5 of the Adobe PDF Reference, third edition (PDF 1.4), with Tables 3.21, 4.12–4.21, 4.35, 4.39 and 4.40; §8.6 of ISO 32000-1:2008 (PDF 1.7), with Tables 33, 62–74, 89, 93 and 94; and §8.6 of ISO 32000-2:2020 (PDF 2.0). The notes on PDF 1.0 and on default color spaces come from the PDF 1.0, 1.1, 1.2 and 1.3 references.