The Page Object Accessing Page Properties


The essential parts of a PDF document are its pages. A page is represented in SetaPDF-Core by the SetaPDF_Core_Document_Page class which can be created individually or accessed by a documents Pages object

Get the Page Size

The Page class offers getter methods for the page width and height: 


Get the height of the page.


Get the width of the page.


Get width and height of the page.

If you need to check a page size against another predefined or individual page size, just pass the page instance to the static is() method of the SetaPDF_Core_PageFormats class: 

$orientation = \SetaPDF_Core_PageFormats::is(\SetaPDF_Core_PageFormats::A4, $page);
if ($orientation === \SetaPDF_Core_PageFormats::ORIENTATION_PORTRAIT) {
    // $page is A4 in portrait
} elseif ($orientation === \SetaPDF_Core_PageFormats::ORIENTATION_LANDSCAPE) {
    // $page is A4 in landscape
} else {
    // $page is not A4

// or 

if (\SetaPDF_Core_PageFormats::is([100, 100], $page) === false) {
    // $page is not 100pt x 100pt

To change the size of a page, you will need to change its page boundaries.

Page Boundaries

To get access to all available page boundary boxes the class offers several getter and setter methods: 


Get the art box of this page.


Get the bleed box of this page.


Get a page boundary box of the page.


Get the crop box of this page.


Get the media box of this page.


Get the trim box of this page.


Set the art box.


Set the bleed box.


Set a boundary box.


Set the crop box.


Set the media box.


Set the trim box.

All these methods are proxy methods to the getBoundary() and setBoundaryBox() which allows you to pass the boundary name as a parameter, too. The page boundary boxes are available through class constants shown here.

By default all setter methods will check the given box values for validity. This means that the crop, bleed, trim and art boxes need to fit into the media box and vice versa.

To ignore this behaviour just pass false to the $checkBoundary parameter.

Page Rotation

To get and set the rotation of a page the class also offers some getter and setter methods: 


Get the page rotation.


Rotate a page by degrees.


Set the page rotation.

Page Orientation

To get the orientation of a page the class also offers a simple helper method:


Get the orientation of the page.


The annotations instance of a page can be accessed through the getAnnotations() method: 


Gets the annotation instance of this page.


The contents object is an object allowing you a low level access to all content streams related to the page. 

It can be accessed through the getContents() method: 


Gets the contents instance of this page.

Encapsulate Existing Content in a Graphic State

If you need to edit an existing page content stream without knowing its structure or without parsing and interpreting its graphic state you should encapsulate the existing content in a separate graphic state. You can do this with the encapsulateExistingContentInGraphicState() method of the contents class. 


The canvas instance of a page can be accessed through the getCanvas() method: 


Gets the canvas instance for this page.

Additional Actions

The additional actions instance of a page can be accessed through the getAdditionalActions() method: 


Gets the additional actions object instance for this page.

Transform a Page Into a Form XObject

It is possible to convert a page of an existing PDF document into a reusable structure called a form XObject. You can use this structure e.g. to draw it onto a canvas of another page or onto a canvas of an annotation appearance. 

You can convert a page into a form XObject with the toXObject() method: 


Converts the page object into a form XObject.

$document : SetaPDF_Core_Document
$box : string

The name of the bounding box


Throws SetaPDF_Exception_NotImplemented

Throws SetaPDF_Core_Type_Exception