PHP
  Home arrow PHP arrow Page 5 - PDF Generation With PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
PHP

PDF Generation With PHP
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 87
    2002-08-14


    Table of Contents:
  • PDF Generation With PHP
  • Getting Started
  • Anatomy Lesson
  • Pretty As A Picture
  • The Shortest Distance Between Two Points
  • Square Peg, Round Hole
  • Heaven Is A Place On Earth
  • Piece Of Pie

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    PDF Generation With PHP - The Shortest Distance Between Two Points
    ( Page 5 of 8 )

    Why stop there? PHP's PDF extension comes with a whole bag of functions designed to let you draw lines, circles and other shapes in your PDF document. Consider the following example, which demonstrates the process of drawing a line.
    <?php
    // create handle for new PDF document
    $pdf = pdf_new();
    
    // open a file
    pdf_open_file($pdf, "letterhead.pdf");
    
    // start a new page (A4)
    pdf_begin_page($pdf, 595, 842);
    
    // get and use a font object
    $arial = pdf_findfont($pdf, "Arial", "host", 1); pdf_setfont($pdf,$arial, 12);
    
    // set a colour for the line
    pdf_setcolor($pdf, "stroke", "rgb", 0, 0, 0);
    
    // place a logo in the top left corner
    $image = pdf_open_image_file($pdf, "jpeg", "logo.jpg");
    pdf_place_image($pdf, $image, 50, 785, 0.5);
    
    // draw a line under the logo
    pdf_moveto($pdf, 20, 780);
    pdf_lineto($pdf, 575, 780);
    pdf_stroke($pdf);
    
    // draw another line near the bottom of the page 
    pdf_moveto($pdf, 20,50); 
    pdf_lineto($pdf, 575, 50); pdf_stroke($pdf);
    
    // and write some text under it
    pdf_show_xy($pdf, "Confidential and proprietary", 200, 35);
    
    // end page
    pdf_end_page($pdf);
    
    // close and save file
    pdf_close($pdf);
    ?>
    Here's what you should see in the PDF document



    In this case, the process of drawing a line involves creative use of the pdf_moveto(), pdf_lineto() and pdf_stroke() functions.

    In the example above, I'd like to draw a line from the position (20,780) to the new position (575, 780). In order to do this, I first need to place the cursor at the starting point (20,780), via a call to pdf_moveto().
    pdf_moveto($pdf, 20, 780);
    Next, I need to set the end point of the line, via pdf_lineto():
    pdf_lineto($pdf, 575, 780);
    Finally, the line is actually rendered using pdf_stroke().
    pdf_stroke($pdf);
    The stroke colour is set via a call to pdf_setcolor(), which accepts a number of parameters: the PDF document handle, whether the colour being set is for "stroke", "fill" or "both", the colour scheme to use (RGB or CMYK), and a list of colour values appropriate to the selected colour scheme.
    pdf_setcolor($pdf, "stroke", "rgb", 0, 0, 0);
    It's important to note that the list of colour values provided to pdf_setcolor() must be specified in terms of percentage intensity - that is, the intensity of that colour, expressed as a percentage of the maximum intensity possible. So, if I wanted to set red (RGB: 255,0,0) as the stroke colour, my call to pdf_setcolor() would look like this,
    pdf_setcolor($pdf, "stroke", "rgb", 1, 0, 0);
    while a fill colour of yellow (RGB: 255,255,0) would be
    pdf_setcolor($pdf, "fill", "rgb", 1, 1, 0);


     
     
    >>> More PHP Articles          >>> More By icarus, (c) Melonfire
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT