PHP
  Home arrow PHP arrow Page 5 - PDF Generation With PHP
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 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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 / 73
    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 - 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


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

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT