Zend
  Home arrow Zend arrow 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 1 of 8 )

    This tutorial is intended for the PHP programmer who needs to incorporate PDF generation in a script without using external libraries such as PDFlib (often unavailable due to licensing restrictions or lack of funds). This tutorial is the second of two parts, and builds on what was covered in the first part. Therefore, if you have not yet gone through Part 1, you are advised to do so (or at least read through it), before going through this tutorial (Part 2). Apart from what was dealt with in Part 1, no knowledge of PDF file structure is required to understand this tutorial, as all references are explained.

    We saw in Part 1 how PDF files are, after all, just plain text files, with specific markup syntax that describes what should happen to objects within the document, such as text and images. We shall now further examine this syntax, to allow us to create a more complete PDF document (i.e more than simple text).

    Learning Objectives
    With the combined knowledge from Part 1, and from the current tutorial (Part 2), you should be able to put together a simple PDF class that can:
      • Add colors to your PDF documents;
      • Add lines, rectangles and circles;
      • Insert JPEG images.

    Prerequisites
    You need to have a fully functional PHP install (either PHP 4 or PHP 5), and a running web server to output the PDF file from your script.

    Acrobat Reader, XPDF, or equivalent is required, to display the results of your work.

    You do not need any external library, either separate or compiled into PHP, to generate your PDF files.

    How It Works
    We already have the class from Part 1 of this tutorial. In Part 2 we will just add a few more class variables and methods to it.

    We shall review the various methods and features of the PDF language, and then finally put it all together as one class.

    New Class Variables
    In addition to the class variables we introduced in Part 1, we will also need the following.
    var $_fill_color = '0 g';  // Color used on text and fills.
    var $_draw_color = '0 G';  // Line draw color.
    var $_line_width = 1;      // Drawing line width.
    var $_images = array();    // An array of used images.
    In the PDF specifications, black is the default value for fill and draw colors, and the default line width is 1 point. Therefore we will use these values as our class defaults for the above variables.

    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 4 hosted by Hostway