NAME
PDF::Make::Color - Color spaces and color conversion
SYNOPSIS
use PDF::Make::Document;
use PDF::Make::Color;
my $doc = PDF::Make::Document->new;
$doc->add_page(612, 792);
# Create an sRGB color space (CalRGB with D65 white point)
my $srgb = PDF::Make::Color->srgb;
$srgb->write_to_doc($doc);
# Create a spot (separation) color
my $spot = PDF::Make::Color->separation('PANTONE 185 C',
0, 0.81, 0.69, 0); # CMYK fallback
$spot->write_to_doc($doc);
# Inspect
print $srgb->name, "\n"; # sRGB
print $srgb->components, "\n"; # 3
# Color conversions (class methods)
my ($c, $m, $y, $k) = PDF::Make::Color->rgb_to_cmyk(1.0, 0, 0);
my ($r, $g, $b) = PDF::Make::Color->cmyk_to_rgb(0, 1, 1, 0);
my ($r2, $g2, $b2) = PDF::Make::Color->hex_to_rgb('#ff6600');
DESCRIPTION
PDF::Make::Color manages PDF color spaces and provides color conversion utilities. Supports Device color spaces (RGB, CMYK, Gray), CIE-based spaces (sRGB as CalRGB), and Separation spaces (spot colors).
CLASS METHODS
srgb()
my $cs = PDF::Make::Color->srgb;
Creates an sRGB color space object (CalRGB with D65 white point and sRGB gamma/matrix). This is the standard color space for screen-oriented PDFs.
separation($name, $c, $m, $y, $k)
my $cs = PDF::Make::Color->separation('Reflex Blue',
1.0, 0.8, 0, 0.02);
Creates a Separation (spot) color space. The CMYK values define the fallback appearance when the spot ink is not available.
rgb_to_cmyk($r, $g, $b)
my ($c, $m, $y, $k) = PDF::Make::Color->rgb_to_cmyk(1.0, 0.5, 0);
Converts RGB values (0.0-1.0) to CMYK (0.0-1.0). Uses a simple UCR model.
cmyk_to_rgb($c, $m, $y, $k)
my ($r, $g, $b) = PDF::Make::Color->cmyk_to_rgb(0, 1, 1, 0);
Converts CMYK values (0.0-1.0) to RGB (0.0-1.0).
hex_to_rgb($hex)
my ($r, $g, $b) = PDF::Make::Color->hex_to_rgb('#ff6600');
my ($r, $g, $b) = PDF::Make::Color->hex_to_rgb('3498db');
Converts a hex color string to RGB (0.0-1.0). Accepts with or without leading #. Croaks on invalid input.
INSTANCE METHODS
name()
my $n = $cs->name;
Returns the color space name (e.g. 'sRGB', 'Reflex Blue').
components()
my $n = $cs->components;
Returns the number of color components (3 for RGB, 4 for CMYK, 1 for Separation).
write_to_doc($doc)
my $obj_num = $cs->write_to_doc($doc);
Writes the color space dictionary into the document. Returns the PDF object number.