Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Page Creation

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. Attached pages can't be used with another PDF documents until it's not cloned. See Page cloning section for the details.

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:

  • Zend_Pdf_Page::SIZE_A4

  • Zend_Pdf_Page::SIZE_A4_LANDSCAPE

  • Zend_Pdf_Page::SIZE_LETTER


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 660. PDF document pages management

// Reverse page order
$pdf->pages array_reverse($pdf->pages);
// Add new page
$pdf->pages[] = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
// Add new page
$pdf->pages[] = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);

// Remove specified page.


Zend Framework