org.apache.pdfbox.pdmodel.graphics.color

## Class PDColor

- java.lang.Object
- - org.apache.pdfbox.pdmodel.graphics.color.PDColor

    public final class PDColor
    extends Object

A color value, consisting of one or more color components, or for pattern color spaces, a name and optional color components. Color values are not associated with any given color space. Instances of PDColor are immutable.

Author:
  John Hewson

### Constructor Summary

Constructors
Constructor and Description
`PDColor(COSArray array, PDColorSpace colorSpace)` Creates a PDColor containing the given color value.
`PDColor(COSName patternName, PDColorSpace colorSpace)` Creates a PDColor containing the given pattern name.
`PDColor(float[] components, COSName patternName, PDColorSpace colorSpace)` Creates a PDColor containing the given color component values and pattern name.
`PDColor(float[] components, PDColorSpace colorSpace)` Creates a PDColor containing the given color component values.

### Method Summary

All Methods Instance Methods Concrete Methods
`PDColorSpace` `getColorSpace()` Returns the color space in which this color value is defined.
`float[]` `getComponents()` Returns the components of this color value.
`COSName` `getPatternName()` Returns the pattern name from this color value.
`boolean` `isPattern()` Returns true if this color value is a pattern.
`COSArray` `toCOSArray()` Returns the color component values as a COS array
`int` `toRGB()` Returns the packed RGB value for this color, if any.
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### PDColor

    public PDColor(COSArray array,
                   PDColorSpace colorSpace)

Creates a PDColor containing the given color value.

Parameters:
  `array` - a COS array containing the color value
  `colorSpace` - color space in which the color value is defined

#### PDColor

    public PDColor(float[] components,
                   PDColorSpace colorSpace)

Creates a PDColor containing the given color component values.

Parameters:
  `components` - array of color component values
  `colorSpace` - color space in which the components are defined

#### PDColor

    public PDColor(COSName patternName,
                   PDColorSpace colorSpace)

Creates a PDColor containing the given pattern name.

Parameters:
  `patternName` - the name of a pattern in a pattern dictionary
  `colorSpace` - color space in which the pattern is defined

#### PDColor

    public PDColor(float[] components,
                   COSName patternName,
                   PDColorSpace colorSpace)

Creates a PDColor containing the given color component values and pattern name.

Parameters:
  `components` - array of color component values
  `patternName` - the name of a pattern in a pattern dictionary
  `colorSpace` - color space in which the pattern/components are defined

### Method Detail

#### getComponents

    public float[] getComponents()

Returns the components of this color value.

Returns:
  the components of this color value, never null.

#### getPatternName

    public COSName getPatternName()

Returns the pattern name from this color value.

Returns:
  the pattern name from this color value

#### isPattern

    public boolean isPattern()

Returns true if this color value is a pattern.

Returns:
  true if this color value is a pattern

#### toRGB

    public int toRGB()
              throws IOException

Returns the packed RGB value for this color, if any.

Returns:
  RGB
Throws:
  `IOException` - if the color conversion fails
  `UnsupportedOperationException` - if this color value is a pattern.

#### toCOSArray

    public COSArray toCOSArray()

Returns the color component values as a COS array

Returns:
  the color component values as a COS array

#### getColorSpace

    public PDColorSpace getColorSpace()

Returns the color space in which this color value is defined.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`