Caution: The documentation you are viewing is
for an older version of Zend Framework.
You can find the documentation of the current version at docs.zendframework.com
Working with Pages - Zend_Pdf
Working with Pages
The pages in a PDF document are represented as Zend_Pdf_Page instances in Zend_Pdf.
PDF pages either are loaded from an existing PDF or created using the Zend_Pdf API.
New pages can be created by instantiating new Zend_Pdf_Page objects directly or by calling the Zend_Pdf::newPage() method, which returns a Zend_Pdf_Page object. Zend_Pdf::newPage() creates a page that is already attached to a document. Unattached pages can't be used with multiple PDF documents, but they are somewhat more performant. 
The Zend_Pdf::newPage() method and the Zend_Pdf_Page constructor take the same parameters specifying page size. They can take either the size of page ($x, $y) in points (1/72 inch) or a predefined constant representing a page type:
Document pages are stored in the $pages public attribute of the Zend_Pdf class. The attribute holds an array of Zend_Pdf_Page objects and completely defines the instances and order of pages. This array can be manipulated like any other PHP array:
Example #1 PDF document pages management
Existing PDF page can be cloned by creating new Zend_Pdf_Page object with existing page as a parameter:
Example #2 Cloning existing page
- // Store template page in a separate variable
- $template = $pdf->pages[$templatePageIndex];
- // Add new page
- $page1 = new Zend_Pdf_Page($template);
- $pdf->pages = $page1;
- // Add another page
- $page2 = new Zend_Pdf_Page($template);
- $pdf->pages = $page2;
- // Remove source template page from the documents.
It's useful if you need several pages to be created using one template.
Important! Cloned page shares some PDF resources with a template page, so it can be used only within the same document as a template page. Modified document can be saved as new one.