Index
- Installation
- Getting Started
- Memory Usage
- Readers and Writers
- The Document Class
- Metadata
- Pages
- Canvas
- Page Layout and Mode
- Viewer Preferences
- Document Outline
- Page Labels
- Actions
- Destinations
- Annotations
- 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
Table of Contents
Introduction
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.
Colors
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:
Description
Create an instance by a PDF array object, PHP array or a hexadecimal string of an RGB value.
Parameters
- $components : int|float|string|array|SetaPDF_Core_Type_Array
Exceptions
Throws InvalidArgumentException
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 SetaPDF_Core_DataStructure_Color_Gray
, SetaPDF_Core_DataStructure_Color_Rgb
, SetaPDF_Core_DataStructure_Color_Cmyk
classes:
$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');
Color Spaces
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 - 8.6.6.4 Separation Colour Spaces):