Zend
  Home arrow Zend arrow Page 9 - 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

    Application developers can seamlessly integrate the Advantage Database install with their application install. Learn the best practices used when setting up silent installs with this seminar.

    PDFs with PHP part 1 - Compression
    (Page 9 of 10 )


    If compression is required page content will be passed through the gzcompress() function before being written to output. Here you also can see why the $_n object counter starts from 2. We set the root pages parent as object number 1, and later you will see that we set resources as object number 2. This is just so that it is easier for us to reference these when required, for example in each page object.


    function _putPages() 

        
    /* If compression is required set the compression tag. */ 
        $filter 
    = ($this->_compress) ? '/Filter /FlateDecode ' ''
        
    /* Print out pages, loop through each. */ 
        
    for ($n 1$n <= $this->_page$n++) { 
            $this
    ->_newobj();                 // Start a new object. 
            $this->_out('<</Type /Page');     // Object type. 
            $this->_out('/Parent 1 0 R'); 
            $this->_out('/Resources 2 0 R'); 
            $this->_out('/Contents ' . ($this->_n + 1) . ' 0 R>>'); 
            $this->_out('endobj'); 
            /* If compression required gzcompress() the page content. */ 

            $p 
    = ($this->_compress) ? gzcompress($this->_pages[$n]) : $this->_pages[$n]; 
            
    /* Output the page content. */ 
            $this
    ->_newobj();                 // Start a new object. 
            $this->_out('<<' . $filter . '/Length ' . strlen($p) . '>>'); 
            $this->_putStream($p);            // Output the page. 
            $this->_out('endobj'); 
        } 
        /* Set the offset of the first object. */ 

        $this
    ->_offsets[1] = strlen($this->_buffer); 
        $this
    ->_out('1 0 obj'); 
        $this
    ->_out('<</Type /Pages'); 
        $kids 
    '/Kids ['
        
    for ($i 0$i $this->_page$i++) { 
            $kids 
    .= ($i) . ' 0 R '
        
    }    
        $this
    ->_out($kids ']'); 
        $this
    ->_out('/Count ' $this->_page); 
        
    /* Output the page size. */ 
        $this
    ->_out(sprintf('/MediaBox [0 0 %.2f %.2f]'
                            $this
    ->_w$this->_h)); 
        $this
    ->_out('>>'); 
        $this
    ->_out('endobj'); 




    Let’s look at another method now: _putStream(). We could have included the code in the actual _putPages() function, however, since this method is required for other objects (such as images), we might as well separate it out now.


    function _putStream($s

        $this
    ->_out('stream'); 
        $this
    ->_out($s); 
        $this
    ->_out('endstream'); 




    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

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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