Pdf

PDF Color class Extension points: getPdfColor() and getColorObject().

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

From Web