Zend
  Home arrow Zend arrow Page 3 - 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 
IBM Developerworks
 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 - The Factory Method
    (Page 3 of 10 )


    This method will give us the PDF object with which we can build our document. It sets the initial values for the document, such as page orientation and size, and returns the object.

     
    function &factory($orientation 'P'$format 'A4'

        
    /* Create the PDF object. */ 
        $pdf 
    = &new PDF(); 
        
    /* Page format. */ 
        $format 
    strtolower($format); 
        
    if ($format == 'a3') {           // A3 page size. 
            $format = array(841.89, 1190.55); 
        } elseif ($format == 'a4') {     // A4 page size. 
            $format = array(595.28, 841.89); 
        } elseif ($format == 'a5') {     // A5 page size. 
            $format = array(420.94, 595.28); 
        } elseif ($format == 'letter') { // Letter page size. 
            $format = array(612, 792); 
        } elseif ($format == 'legal') {  // Legal page size. 
            $format = array(612, 1008); 
        } else { 
            die(sprintf('Unknown page format: %s', $format)); 
        }    
        $pdf->_w = $format[0]; 
        $pdf->_h = $format[1]; 
        /* Page orientation. */ 

        $orientation 
    strtolower($orientation); 
        
    if ($orientation == 'l' || $orientation == 'landscape') { 
            $w 
    $pdf->_w
            $pdf
    ->_w $pdf->_h
            $pdf
    ->_h $w
        
    } elseif ($orientation != 'p' && $orientation != 'portrait') { 
            
    die(sprintf('Incorrect orientation: %s'$orientation)); 
        

        
    /* Turn on compression by default. */ 
        $pdf
    ->setCompression(true); 
        return 
    $pdf



    Also in this method we turn on compression by default. This makes the output PDF files a lot smaller.

    The actual setCompression() method is as follows:


    function setCompression($compress
    {    
        
    /* If no gzcompress function is available then default to 
         * false. */ 

        $this
    ->_compress = (function_exists('gzcompress') ? $compress false); 



    However, whilst learning you may wish to explicitly turn off compression, so that you can open your created PDF document with a text editor and see easily what is happening.

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