- Getting Started
- Memory Usage
- Readers and Writers
- The Document Class
- Page Layout and Mode
- Viewer Preferences
- Document Outline
- Page Labels
- Embedded File Streams
- Colors and Color Spaces
- Page Formats and Boundaries
- Standard and Public Key Encryption
- Fonts and Encodings
- Corrupted Documents
- Reader Enabled Documents
- Refactor Old SetaPDF Code
- API Reference
Colors and Color Spaces Using Colors in SetaPDF
Colors could be defined and used in various ways in a PDF file. The SetaPDF-Core component offers several classes to handle a wide range of available color spaces and values.
Color values are represented by color classes. These instances are mostly used internal by a component to use such color for drawing in or writing text to a canvas object.
If a components class offers a method to define a color, it requires a color instance or it will forward the argument to a static method which will create a component by the given color components:
Create an instance by a PDF array object, PHP array or a hexadecimal string of an RGB value.
- $components : int|float|string|array|SetaPDF_Core_Type_Array
The count of $components define the color space (1 - gray, 3 - RGB, 4 - CMYK). The color values must be between 0 and 1.
It is also possible to pass a hexadecimal string of an RGB value. The string need to be prefixed by a sharp (#).
For sure it is possible to initiate a color object manually by passing the components to its constructor. Common color values could be created with the
$red = new SetaPDF_Core_DataStructure_Color_Rgb(1, 0, 0); // the components could also be passed as array $green = new SetaPDF_Core_DataStructure_Color_Rgb(array(0, 1, 0)); $blue = new SetaPDF_Core_DataStructure_Color_Rgb(0, 0, 1); $gray = new SetaPDF_Core_DataStructure_Color_Gray(.3); $orange = new SetaPDF_Core_DataStructure_Color_Cmyk(0, .35, 1, 0); $violet = new SetaPDF_Core_DataStructure_Color_Cmyk(array(.07, .39, 0, .4)); $limegreen = SetaPDF_Core_DataStructure_Color::createByComponents('#32CD32');
The SetaPDF-Core component offers classes for defining color spaces. The color classes mentioned earlier will define their own color space when they were invoked by an operator in a content stream.
In the PDF format it is also possible to declare color components for a currently activated color space. This is needed for example for a Separation color space (see PDF 32000-1:2008 - 22.214.171.124 Separation Colour Spaces):