Zend
  Home arrow Zend arrow Page 2 - PDFs with PHP part 1
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 1
By: Zend
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2004-01-06

    Table of Contents:
  • PDFs with PHP part 1
  • Prerequisites
  • The Factory Method
  • Writing Content
  • Adding a Page
  • And Now to Output the Text
  • Closing the Document
  • The Trailer
  • Compression
  • Resources

  • 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 1 - Prerequisites
    (Page 2 of 10 )


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

    Acrobat Reader, XPDF, or an equivalent is required to see 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

    The best approach is to set the code up as a class. This allows for greater flexibility later.

    The primary (public) methods deal with the main operations on a PDF document: setting it up, adding pages, setting font, adding text, activating compression, and output of the document.

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

    Setting up Class Variables
    We will need a few class variables to keep track of output, pages, objects, settings, etc.

    The following is a list of the essential variables, with brief comments. You will later see each one of these variables in its context, which will give you a better idea of how they are used. For now just briefly get yourself acquainted with them.
    var $_buffer = '';          // Buffer holding in-memory PDF. var $_state = 0;            // Current document state.
    var $_page = 0;             // Current page number.
    var $_n = 2;                // Current object number.
    var $_offsets = array();    // Array of object offsets.
    var $_pages = array();      // Array containing the pages.
    var $_w;                    // Page width in points.
    var $_h;                    // Page height in points
    var $_fonts = array();      // An array of used fonts.
    var $_font_family = '';     // Current font family.
    var $_font_style = '';      // Current font style.
    var $_current_font;         // Array with current font info. var $_font_size = 12;       // Current font size in points.
    var $_compress;             // Flag to compress or not.
    var $_core_fonts = array('courier'=> 'Courier',
                             'courierB'=> 'Courier-Bold',
                             'courierI'=> 'Courier-Oblique',
                             'courierBI'=> 'Courier-BoldOblique',
                             'helvetica'=> 'Helvetica',
                             'helveticaB'=> 'Helvetica-Bold',
                             'helveticaI'=> 'Helvetica-Oblique',
                             'helveticaBI'=> 'Helvetica-BoldOblique',
                             'times'=> 'Times-Roman',
                             'timesB'=> 'Times-Bold',
                             'timesI'=> 'Times-Italic',
                             'timesBI'=> 'Times-BoldItalic',
                             'symbol'=> 'Symbol',
                             'zapfdingbats' => 'ZapfDingbats');

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