PDFs with PHP part 2 - RGB Color (Page 3 of 8 )
Selecting 'rgb' and passing three color components gives us full color, represented by 3 separate 3-decimal-place numbers, followed by the letters 'rg'.
So, for example:
'0.800 0.400 0.200 rg' = purple-ish color. eg. setFillColor('rgb', 0.8, 0.4, 0.2)
A second, very similar function sets the drawing color:
function setDrawColor
($cs = 'rgb', $c1, $c2 = 0, $c3 = 0,
$c4 = 0)
{
$cs = strtolower($cs);
if ($cs = 'rgb') {
$this->_draw_color = sprintf('%.3f %.3f %.3f RG',
$c1, $c2, $c3);
} elseif ($cs = 'cmyk') {
$this->_draw_color = sprintf('%.3f %.3f %.3f %.3f K',
$c1, $c2, $c3, $c4);
} else {
$this->_draw_color = sprintf('%.3f G', $c1);
}
/* If document started output to buffer. */
if ($this->_page > 0) {
$this->_out($this->_draw_color);
}
}
Note that the only difference between these two functions is the lowercase/uppercase syntax. 'g', 'rg', and 'k' specify fill color, while 'G', 'RG', and 'K', specify draw color.
That's it! Calling either of these two functions will set the colors for any subsequent text or drawing output to your PDF document, and preserve that setting between pages.
Next: Line Drawing >>
More Zend Articles
More By Zend