Table of contents
Namespace: Com\Tecnick\Color
class Pdf extends Spot implements PdfColorWriterInterface
Extends: Spot
Implements: PdfColorWriterInterface
Source: src/Pdf.php:39
PDF Color class
Extension points: getPdfColor() and getColorObject(). A subclass overriding either must mirror the signature exactly. Every other method is final.
Constants
JSCOLOR
Array of valid JavaScript color names to be used in PDF documents
public const JSCOLOR = ['transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray']
Source: src/Pdf.php:44
Methods
getColorObject()
Returns a color object from an HTML, CSS or Spot color representation.
NOTE: this is a read-only lookup. A spot color referenced here is resolved but NOT registered, so it does not affect the output of getPdfSpotObjects() and getPdfSpotResources(). Use getPdfColor() or addSpotColor() to register a spot color for emission. The returned model is a copy of the registered one.
Spot colors are resolved first. Eight of the eleven default spot color names are also CSS color names (‘red’, ‘green’, ‘blue’, ‘cyan’, ‘magenta’, ‘yellow’, ‘black’, ‘white’) and resolve to the spot color. They agree with their CSS namesake except ‘green’: the spot Green is CMYK(1,0,1,0) = #00ff00, while CSS green is #008000. Pass $allowSpot = false to skip the spot lookup and get the device color. ‘key’, ‘all’ and ’none’ are spot-only names: with $allowSpot = false they yield null.
public getColorObject(string $color, bool $allowSpot = true): ?Model
Parameters:
$color(string): HTML, CSS or Spot color to parse$allowSpot(bool): True to resolve spot colors, false to force a device color.
Returns: ?Model
Source: src/Pdf.php:106
getJsColorString()
Convert color to javascript string
The JSCOLOR names are matched case-sensitively and emitted verbatim as Acrobat JavaScript identifiers (‘color.dkGray’). A name that differs only in case falls through to the color parser and yields a component array.
final public getJsColorString(string $color): string
Parameters:
$color(string): color name or color object
Returns: string
Source: src/Pdf.php:68
getPdfCmykComponents()
Get the CMYK color components format used in PDF documents.
Returns an empty string if the color cannot be resolved.
final public getPdfCmykComponents(string $color, bool $allowSpot = true): string
Parameters:
$color(string): HTML, CSS or Spot color to parse$allowSpot(bool): True to resolve spot colors, false to force a device color.
Returns: string
Source: src/Pdf.php:231
getPdfColor()
Get the color components format used in PDF documents NOTE: the alpha channel is omitted
Spot colors are resolved first. Eight of the eleven default spot color names are also CSS color names (‘red’, ‘green’, ‘blue’, ‘cyan’, ‘magenta’, ‘yellow’, ‘black’, ‘white’) and resolve to a Separation color space rather than to DeviceRGB. Pass $allowSpot = false to skip the spot lookup and get a device color. ‘key’, ‘all’ and ’none’ are spot-only names: with $allowSpot = false they yield an empty string.
NOTE: resolving a spot color REGISTERS it, so it is subsequently emitted by getPdfSpotObjects() and getPdfSpotResources(). Call this before getPdfSpotObjects(), so that the returned ‘/CSn cs’ operator references an existing resource. Use getColorObject() for a lookup with no side effect.
Returns an empty string both for a transparent color and for input that cannot be parsed.
NOTE: $tint is the operand of the ‘scn’ operator and applies to spot colors only; a device color is always written at full intensity.
public getPdfColor(
string $color,
bool $stroke = false,
float $tint = 1,
bool $allowSpot = true
): string
Parameters:
$color(string): HTML, CSS or Spot color to parse$stroke(bool): True for stroking (lines, drawing) and false for non-stroking (text and area filling).$tint(float): Intensity of the color (from 0 to 1; 1 = full intensity). Spot colors only.$allowSpot(bool): True to resolve (and register) spot colors, false to force a device color.
Returns: string
Source: src/Pdf.php:152
getPdfFillColor()
Get the fill color components format used in PDF documents.
final public getPdfFillColor(string $color, float $tint = 1, bool $allowSpot = true): string
Parameters:
$color(string): HTML, CSS or Spot color to parse$tint(float): Intensity of the color (from 0 to 1; 1 = full intensity). Spot colors only.$allowSpot(bool): True to resolve (and register) spot colors, false to force a device color.
Returns: string
Source: src/Pdf.php:199
getPdfRgbComponents()
Get the RGB color components format used in PDF documents
Returns an empty string if the color cannot be resolved.
final public getPdfRgbComponents(string $color, bool $allowSpot = true): string
Parameters:
$color(string): HTML, CSS or Spot color to parse$allowSpot(bool): True to resolve spot colors, false to force a device color.
Returns: string
Source: src/Pdf.php:212
getPdfStrokeColor()
Get the stroked color components format used in PDF documents.
final public getPdfStrokeColor(string $color, float $tint = 1, bool $allowSpot = true): string
Parameters:
$color(string): HTML, CSS or Spot color to parse$tint(float): Intensity of the color (from 0 to 1; 1 = full intensity). Spot colors only.$allowSpot(bool): True to resolve (and register) spot colors, false to force a device color.
Returns: string
Source: src/Pdf.php:187
Inherited members
From Css
From Spot
- DEFAULT_SPOT_COLORS: Array of default Spot colors Color keys must be in lowercase and without spaces.
- addSpotColor(): Add a new spot color or overwrite an existing one with the same name.
- addSpotColorFromArray(): Add a new spot color from an array of CMYK components.
- addSpotLabColor(): Add a new Lab-based spot color or overwrite an existing one with the same name.
- encodeSpotColorName(): Encode a spot color name as a PDF name object.
- getPdfSpotObjects(): Returns the PDF command to output Spot color objects.
- getPdfSpotResources(): Returns the PDF command to output Spot color resources.
- getPdfSpotResourcesByKeys(): Returns the PDF command to output the Spot color resources for the given keys.
- getSpotColor(): Return the requested spot color data array, registering it on first use.
- getSpotColorObj(): Return a copy of the requested spot color CMYK object.
- getSpotColors(): Returns the array of spot colors.
- getSpotLabColorObj(): Return a copy of the requested spot color Lab object.
- normalizeSpotColorName(): Return the normalized case-insensitive version of the spot color name to be used as key.
From Web
- WEBHEX: Maps WEB safe color names with their hexadecimal representation (#RRGGBBAA).
- extractHexCode(): Extract the hexadecimal code from the input string and add the alpha channel if missing
- getClosestWebColor(): Get the name of the closest web color
- getClosestWebColorByDeltaE(): Get the name of the perceptually closest web color.
- getClosestWebColorByDeltaEFromString(): Get the name of the perceptually closest web color from a color definition string.
- getClosestWebColorFromString(): Get the name of the closest web color from a color definition string.
- getColorObj(): Parse the input color string and return the corresponding color object
- getHexFromName(): Get the color hexadecimal hash code from name
- getLabSquareDistance(): Get the square of the CIE76 color difference between 2 Lab points.
- getNameFromHex(): Get the color name code from hexadecimal hash
- getRgbObjFromHex(): Get the RGB color object from hexadecimal hash
- getRgbObjFromName(): Get the RGB color object from color name
- getRgbSquareDistance(): Get the square of the distance between 2 RGB points
- normalizeValue(): Get the normalized value from [0..$max] to [0..1]
- tryGetColorObj(): Parse the input color string, returning null instead of raising.