Programmer's Reference Guide

37.2. Creating and loading PDF documents.

Zend_Pdf class represents PDF document itself and provides document level functionality.

To create new document new Zend_Pdf object should be created.

Zend_Pdf class also provides two static methods to load existing PDF. These are Zend_Pdf::load() and Zend_Pdf::parse() methods. Both of them return Zend_Pdf object as a result or throw an exception if error occurs.

Example 37.1. Create new or load existing PDF document.


...
// Create new PDF document.
$pdf1 = new Zend_Pdf();

// Load PDF document from a file.
$pdf2 = Zend_Pdf::load($fileName);

// Load PDF document from a string.
$pdf3 = Zend_Pdf::parse($pdfString);
...

PDF file format supports incremental document update. Thus each time when document is updated, then new revision of the document is created. Zend_Pdf module supports retrieving of specified revision.

Revision can be specified as a second parameter for Zend_Pdf::load() and Zend_Pdf::parse() methods or requested by Zend_Pdf::rollback() [4] call.

Example 37.2. Requesting specified revision of the PDF document.


...
// Load PDF previouse revision of the document.
$pdf1 = Zend_Pdf::load($fileName, 1);

// Load PDF previouse revision of the document.
$pdf2 = Zend_Pdf::parse($pdfString, 1);

// Load first revision of the document.
$pdf3 = Zend_Pdf::load($fileName);
$revisions = $pdf3->revisions();
$pdf3->rollback($revisions - 1);
...



[4] Zend_Pdf::rollback() method must be invoked before any changes, applied to the document. Otherwise behavior is undefined.


Search the Manual

Translation Status Reports

View the current status report of Zend Framework manual translations.