PHP
  Home arrow PHP arrow Page 6 - PDF Generation With PHP
Dev Shed Forums 
Administration  
AJAX  
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 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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: 4 stars4 stars4 stars4 stars4 stars / 72
    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:
      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


    PDF Generation With PHP - Square Peg, Round Hole


    (Page 6 of 8 )

    Lines aren't the only thing you can draw - circles and rectangles also figure prominently on the menu. Take a look at the following example, which demonstrates.

    <?php
    // create handle for new PDF document
    $pdf = pdf_new();
    // open a file
    pdf_open_file($pdf, "shapes.pdf");
    // start a new page (A4)
    pdf_begin_page($pdf, 595, 842);
    // set a fill colour
    pdf_setcolor($pdf, "fill", "rgb", 1, 1, 0);
    // set a stroke colour
    pdf_setcolor($pdf, "stroke", "rgb", 0, 0, 0);
    // draw a rectangle
    pdf_rect($pdf, 50, 500, 200, 300);
    pdf_fill_stroke($pdf);
    // set a fill colour
    pdf_setcolor($pdf, "fill", "rgb", 0, 1, 0);
    // set a stroke colour
    pdf_setcolor($pdf, "stroke", "rgb", 0, 0, 1);
    // draw a circle
    pdf_circle($pdf, 400, 600, 100);
    pdf_fill_stroke($pdf);
    // end page
    pdf_end_page($pdf);
    // close and save file
    pdf_close($pdf);
    ?>
    Here's the output:



    In this case, the pdf_rect() function has been used to draw a rectangle, given the coordinates of the lower left corner and the height and width. This rectangle has then been filled and outlined in two different colours, via the pdf_fill_stroke() function.
    pdf_setcolor($pdf, "fill", "rgb", 1, 1, 0);
    pdf_setcolor($pdf, "stroke", "rgb", 0, 0, 0);
    pdf_rect($pdf, 50, 500, 200, 300);
    pdf_fill_stroke($pdf);
    Circles are handled by the pdf_circle() function, which accepts three arguments: the X and Y coordinates of the circle center, and the length of the circle radius.
    pdf_circle($pdf, 400, 600, 100);
    This ability to draw geometric shapes on the fly can come in handy in a number of different situations. Consider the following one, in which a couple of "for" loops have been combined with the pdf_lineto() function to generate a PDF line grid.
    <?php
    // create handle for new PDF document
    $pdf = pdf_new();
    // open a file
    pdf_open_file($pdf, "grid.pdf");
    // start a new page (A4)
    pdf_begin_page($pdf, 595, 842);
    // set a stroke colour
    pdf_setcolor($pdf, "stroke", "rgb", 0, 0, 0);
    // draw vertical lines (move along X axis)
    for ($x=0; $x<=595; $x+=20)
    {
    pdf_moveto($pdf, $x, 0);
    pdf_lineto($pdf, $x, 842);
    pdf_stroke($pdf);
    }
    // draw horizontal lines (move along Y axis)
    for ($y=0; $y<=842; $y+=20)
    {
    pdf_moveto($pdf, 0, $y);
    pdf_lineto($pdf, 595, $y);
    pdf_stroke($pdf);
    }
    // end page
    pdf_end_page($pdf);
    // close and save file
    pdf_close($pdf);
    ?>
    Here's the output:

    More PHP Articles
    More By icarus, (c) Melonfire


       · This article saved me.I searched a lot for pdf conversion of php file,none but u...
     

       

    PHP ARTICLES

    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application





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