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
- Migrating
- 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 \setasign\SetaPDF2\Core\DataStructure\Color\Gray
, \setasign\SetaPDF2\Core\DataStructure\Color\Rgb
, \setasign\SetaPDF2\Core\DataStructure\Color\Cmyk
classes:
<?php use \setasign\SetaPDF2\Core\DataStructure\Color; $red = new Color\Rgb(1, 0, 0); // the components could also be passed as array $green = new Color\Rgb([0, 1, 0]); $blue = new Color\Rgb([0, 0, 1]); $gray = new Color\Gray(.3); $orange = new Color\Cmyk(0, .35, 1, 0); $violet = new Color\Cmyk([.07, .39, 0, .4]); $limegreen = Color\AbstractColor::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):