Home arrow Zend arrow Page 3 - PDFs with PHP part 2

RGB Color - Zend

This tutorial is intended for the PHP programmer who needs to incorporate PDF generation in a script without using external libraries such as PDFlib (often unavailable due to licensing restrictions or lack of funds). This tutorial is the second of two parts, and builds on what was covered in the first part. Therefore, if you have not yet gone through Part 1, you are advised to do so (or at least read through it), before going through this tutorial (Part 2). Apart from what was dealt with in Part 1, no knowledge of PDF file structure is required to understand this tutorial, as all references are explained.

TABLE OF CONTENTS:
  1. PDFs with PHP part 2
  2. Color
  3. RGB Color
  4. Line Drawing
  5. Circles
  6. Page Add Modifications
  7. File Checking
  8. Example Use
By: Zend
Rating: starstarstarstarstar / 5
January 07, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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.



 
 
>>> More Zend Articles          >>> More By Zend
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

ZEND ARTICLES

- Taking the Zend Certified PHP Engineer Exam:...
- Quick Introduction to PHP 5
- PHP SOAP Extension
- Improving Performance
- PDFs with PHP part 2
- PDFs with PHP part 1
- PHP at Lycos
- Build Database Interfaces

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: