Zend
  Home arrow Zend arrow Page 6 - PDFs with PHP part 2
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ZEND

PDFs with PHP part 2
By: Zend
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2004-01-07

    Table of Contents:
  • PDFs with PHP part 2
  • Color
  • RGB Color
  • Line Drawing
  • Circles
  • Page Add Modifications
  • File Checking
  • Example Use

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    PDFs with PHP part 2 - Page Add Modifications
    (Page 6 of 8 )


    The only code we still need to add for colors and drawings are some checks in the addPage() function. These make sure that the colors and line widths, set before any page is added, are actually inserted into the buffer, and that they are remembered from page to page.

    For the addPage() function, introduced in Part 1, the three if() checks appear below, at the bottom of the function:


    function addPage() 

        $this
    ->_page++;                    // Increment page count. 
        $this->_pages[$this->_page] = '';  // Start the page buffer. 
        $this->_state = 2;                 // Set state to page 
                                           // opened. 
        /* Check if font has been set before this page. */ 
        if ($this->_font_family) { 
            $this->setFont($this->_font_family, $this->_font_style, $this->_font_size); 
        } 
        /* Check if fill color has been set before this page. */ 
        if ($this->_fill_color != '0 g') { 
            $this->_out($this->_fill_color); 
        }    
        /* Check if draw color has been set before this page. */ 
        if ($this->_draw_color != '0 G') { 
            $this->_out($this->_draw_color); 
        } 
        /* Check if line width has been set before this page. */ 
        if ($this->_line_width != 1) { 
            $this->_out($this->_line_width); 
        } 



    Images
    The last step in this tutorial will be a brief look at images: specifically the inserting of the JPEG image type (since it is the simplest one to explain).

     
    function image($file$x$y$width 0$height 0

        
    if (!isset($this->_images[$file])) { 
            
    /* First use of requested image, get the extension. */ 
            
    if (($pos strrpos($file'.')) === false) { 
                
    die(sprintf('Image file %s has no extension and no type was specified'$file)); 
            

            $type 
    strtolower(substr($file$pos 1)); 
            
    /* Check the image type and parse. */ 
            
    if ($type == 'jpg' || $type == 'jpeg') { 
                $info 
    $this->_parseJPG($file); 
            
    } else { 
                
    die(sprintf('Unsupported image file type: %s'$type)); 
            

            
    /* Set the image object id. */ 
            $info
    ['i'] = count($this->_images) + 1
            
    /* Set image to array. */ 
            $this
    ->_images[$file] = $info
        
    } else { 
            $info 
    $this->_images[$file];          // Known image, retrieve 
                                                    // from array. 
        } 
        /* If not specified, do automatic width and height 
         * calculations, either setting to original or 
         * proportionally scaling to one or the other given 
         * dimension. */ 

        
    if (empty($width) && empty($height)) { 
            $width 
    $info['w']; 
            $height 
    $info['h']; 
        
    } elseif (empty($width)) { 
            $width 
    $height $info['w'] / $info['h']; 
        
    } elseif (empty($height)) { 
            $height 
    $width $info['h'] / $info['w']; 
        

        
    $this->_out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q'$width$height$x$this->_h - ($y $height), $info['i'])); 




    More Zend Articles
    More By Zend


     

       

    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




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway