Zend
  Home arrow Zend arrow Page 4 - 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 
eWeek
 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

    Create a Highly Available Database Solution. Advantage Database Server can provide the availability to keep your data safe and ready for your application and users.

    PDFs with PHP part 2 - Line Drawing
    (Page 4 of 8 )


    All that is required for drawing a line in PDF is a starting point and an end point. The below function takes an x1/y1 start, and an x2/y2 end point.

    The actual PDF syntax to achieve this is:
      • 'x1 y1 m' - move the current x/y position to x1/y1;
      • 'x2 y2 l' - continue in a straight line to x2/y2;
      • 'S' - set a “stroke” on the resulting path.
    As in Part 1, we compensate for PDF's inverted y scale by subtracting the user supplied $y value from the $this->_h value for page height, to obtain the vertical distance from the bottom of the page.


    function line($x1$y1$x2$y2
    {    
        $this
    ->_out(sprintf('%.2f %.2f m %.2f %.2f l S'$x1$this->_h $y1$x2$this->_h $y2)); 



    Rectangles
    A rectangle function requires a starting x/y point, a width, and a height. A fifth parameter defines the rectangle style, which can be 'f' for filled, 'd' for drawn, or 'fd' (or 'df', the order doesn’t matter) for both filled and drawn.

    Similar to the line drawing function, the PDF output for the rectangle involves creating a rectangular path and applying a path-painting operator to it:
    • 'x y w h re' - the rectangular path;
    • 'f', 'S' or 'B' - the path-painting operators.


    function rect($x$y$width$height$style ''

        $style 
    strtolower($style); 
        
    if ($style == 'f') { 
            $op 
    'f';      // Style is fill only. 
        } elseif ($style == 'fd' || $style == 'df') { 
            $op = 'B';      // Style is fill and stroke. 
        } else { 
            $op = 'S';      // Style is stroke only. 
        } 
        
    $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s'$x$this->_h $y$width, -$height$op)); 



    Note that the end result of calling a drawn and filled rectangle ('fd') is exactly the same as first creating a filled rectangle ('f') and then creating a drawn one ('d').

    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

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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