The Page Object Accessing Page Properties

Introduction

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: 

getHeight()

Get the height of the page.

getWidth()

Get the width of the page.

getWidthAndHeight()

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: 

PHP
$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: 

getArtBox()

Get the art box of this page.

getBleedBox()

Get the bleed box of this page.

getBoundary()

Get a page boundary box of the page.

getCropBox()

Get the crop box of this page.

getMediaBox()

Get the media box of this page.

getTrimBox()

Get the trim box of this page.

setArtBox()

Set the art box.

setBleedBox()

Set the bleed box.

setBoundary()

Set a boundary box.

setCropBox()

Set the crop box.

setMediaBox()

Set the media box.

setTrimBox()

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: 

getRotation()

Get the page rotation.

rotateBy()

Rotate a page by degrees.

setRotation()

Set the page rotation.

Page Orientation

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

getOrientation()

Get the orientation of the page.

Annotations

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

Description

Gets the annotation instance of this page.

Contents

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: 

Description

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. 

Canvas

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

Description

Gets the canvas instance for this page.

Additional Actions

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

Description

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: 

Description

Converts the page object into a form XObject.

Parameters
$document : SetaPDF_Core_Document
 
$box : string

The name of the bounding box

Exceptions

Throws SetaPDF_Exception_NotImplemented

Throws SetaPDF_Core_Type_Exception