Home arrow Zend arrow Page 8 - PDFs with PHP part 1

The Trailer - Zend

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 will cover only the basics, which hopefully will give you a good start. PDF has a vast set of features and possibilities which can not be covered in a short tutorial. If you need more than what is covered here, you might want to look at some similar yet more complete solutions available, such as the excellent work done by Olivier Plathey on the FPDF class (http://fpdf.org), on which this tutorial is based. Of course, you may wish to take your own route and for that there is also the PDF reference (be warned: itís 1,172 pages!) Basic familiarity with using PHP classes is assumed. Knowledge of PDF file structure is not required, as all references are explained.

TABLE OF CONTENTS:
  1. PDFs with PHP part 1
  2. Prerequisites
  3. The Factory Method
  4. Writing Content
  5. Adding a Page
  6. And Now to Output the Text
  7. Closing the Document
  8. The Trailer
  9. Compression
  10. Resources
By: Zend
Rating: starstarstarstarstar / 9
January 06, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
The final lines to be printed are the PDF trailer.

 
    /* Print trailer. */ 
    $this
->_out('trailer'); 
    $this
->_out('<<'); 
    
/* The total number of objects. */ 
    $this
->_out('/Size ' . ($this->_n 1)); 
    
/* The root object. */ 
    $this
->_out('/Root ' $this->_n ' 0 R'); 
    
/* The document information object. */ 
    $this
->_out('/Info ' . ($this->_n 1) . ' 0 R'); 
    $this
->_out('>>'); 
    $this
->_out('startxref'); 
    $this
->_out($start_xref);  // Where to find the xref. 
    $this->_out('%%EOF'); 
    $this->_state = 3;         // Set the document state to 
                               // closed. 



Now let's look at the new functions weíve met in this document closing method. The _newobj() function above is used simply to keep track of objects added to the document.



function _newobj() 

    
/* Increment the object count. */ 
    $this
->_n++; 
    
/* Save the byte offset of this object. */ 
    $this
->_offsets[$this->_n] = strlen($this->_buffer); 
    
/* Output to buffer. */ 
    $this
->_out($this->_n ' 0 obj'); 




The _putPages() function handles the output of the page content. Here we go through the $_pages array that has been buffering the page content separately, and output it to the main buffer.



 
 
>>> More Zend Articles          >>> More By Zend
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

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

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: