13.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.

例 13.1. Create new or load existing PDF document.

<?php
...
// 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() [3] call.

例 13.2. Requesting specified revision of the PDF document.

<?php
...
// 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);
...
?>


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