public class

Page

extends Object
java.lang.Object
   ↳ com.pdftron.pdf.Page

Class Overview

Page is a high-level class representing PDF page object (see 'Page Objects' in Section 3.6.2, 'Page Tree,' in PDF Reference Manual). Among other associated objects, a page object contains:

  • A series of objects representing the objects drawn on the page (See Element and ElementReader class for examples of how to extract page content)
  • A list of resources used in drawing the page
  • Annotations
  • Beads, private metadata, optional thumbnail image, etc.

Summary

Constants
int e_0 Specifies page rotation, in degrees.
int e_180 The Constant e_180.
int e_270 The Constant e_270.
int e_90 The Constant e_90.
int e_action_trigger_page_close Triggered when the page is closed, This action applies to the page being closed and shall be executed before any other page is opened
int e_action_trigger_page_open Triggered when the page is opened and shall be executed after such an action
int e_art The Constant e_art.
int e_bleed The Constant e_bleed.
int e_crop The Constant e_crop.
int e_media PDF page can define as many as five separate boundaries to control various aspects of the imaging process (for more details please refer to Section 10.10.1 'Page Boundaries' in PDF Reference Manual): - The media box defines the boundaries of the physical medium on which the page is to be printed.
int e_trim The Constant e_trim.
int e_user_crop The Constant e_user_crop.
Public Constructors
Page()
Initialize a page using an existing low-level Cos/SDF page object.
Page(Obj page_dict)
Instantiates a new page from page dictionary
Public Methods
static Page __Create(long impl, Object ref)
long __GetHandle()
static int addRotations(int r0, int r1)
Rotate r0 clockwise by r1
void annotInsert(int pos, Annot annot)
Adds an annotation at the specified location in a page's annotation array.
void annotPushBack(Annot annot)
Adds an annotation to the end of a page's annotation array.
void annotPushFront(Annot annot)
Adds an annotation to the beginning of a page's annotation array.
void annotRemove(int index)
Removes the annoation at a given location.
void annotRemove(Annot annot)
Removes the given annotation from the page.
static int degreeToRotation(int r)
Convert a number that represents rotation in degrees to a rotation enum.
Obj findInheritedAttribute(String attrib)
Some of the page attributes are designated as inheritable.
void flattenField(Field field)
Flatten/Merge existing form field appearances with the page content and remove widget annotation.
Annot getAnnot(int index)
Get the annotation on the page.
Obj getAnnots()
Returns a SDF/Cos array containing annotation dictionaries.
Rect getBox(int type)
Get the box specified page bounding box
Obj getContents()
Get the contents of current page.
Rect getCropBox()
Get the crop box.
Matrix2D getDefaultMatrix(boolean flip_y, int box_type, int rot_type)
Get the default matrix.
Matrix2D getDefaultMatrix()
Get the default matrix.
int getIndex()
Get the page index/number.
Rect getMediaBox()
Get the media box.
int getNumAnnots()
Get the number of annotations on a page.
double getPageHeight()
Get the crop box page height.
double getPageHeight(int box_type)
Get the page height for the given page bounding box
double getPageWidth(int box_type)
Get the page width for the given bounding box
double getPageWidth()
Get the crop box page width.
Obj getResourceDict()
Get the resource dictionary of current page.
int getRotation()
Get the rotation.
Obj getSDFObj()
Get the page dictionary.
Obj getThumb()
Gets the object representing the Image thumbnail.
int[] getThumbInfo()
Gets the associated thumbnail information.
Obj getTriggerAction(int trigger)
Get the Action associated with the selected Page Trigger event.
double getUserUnitSize()
Get the UserUnit value for the page.
Rect getVisibleContentBox()
The bounding box is defined as the smallest rectangle that includes all the visible content on the page.
boolean hasTransition()
Tests whether this page has a transition.
boolean isValid()
Checks if current page is valid.
static int rotationToDegree(int r)
Convert a rotation to a number.
void scale(double scale)
A utility method used to scale physical dimensions of the page including all page content.
void setBox(int type, Rect box)
Set the page bounding box specified by 'page_region' for this page.
void setCropBox(Rect box)
Set the crop box for this page.
void setMediaBox(Rect box)
Set the media box for this page.
void setRotation(int rot_type)
Set the rotation value for this page.
void setUserUnitSize(double unit_size)
Set the UserUnit value for a page.
static int subtractRotations(int r0, int r1)
Rotate r0 counter clockwise by r1.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int e_0

Specifies page rotation, in degrees.

Constant Value: 0 (0x00000000)

public static final int e_180

The Constant e_180.

Constant Value: 2 (0x00000002)

public static final int e_270

The Constant e_270.

Constant Value: 3 (0x00000003)

public static final int e_90

The Constant e_90.

Constant Value: 1 (0x00000001)

public static final int e_action_trigger_page_close

Triggered when the page is closed, This action applies to the page being closed and shall be executed before any other page is opened

Constant Value: 12 (0x0000000c)

public static final int e_action_trigger_page_open

Triggered when the page is opened and shall be executed after such an action

Constant Value: 11 (0x0000000b)

public static final int e_art

The Constant e_art.

Constant Value: 4 (0x00000004)

public static final int e_bleed

The Constant e_bleed.

Constant Value: 2 (0x00000002)

public static final int e_crop

The Constant e_crop.

Constant Value: 1 (0x00000001)

public static final int e_media

PDF page can define as many as five separate boundaries to control various aspects of the imaging process (for more details please refer to Section 10.10.1 'Page Boundaries' in PDF Reference Manual): - The media box defines the boundaries of the physical medium on which the page is to be printed. It may include any extended area surrounding the finished page for bleed, printing marks, or other such purposes. It may also include areas close to the edges of the medium that cannot be marked because of physical limitations of the output device. Content falling outside this boundary can safely be discarded without affecting the meaning of the PDF file. - The crop box defines the region to which the contents of the page are to be clipped (cropped) when displayed or printed. Unlike the other boxes, the crop box has no defined meaning in terms of physical page geometry or intended use; it merely imposes clipping on the page contents. The default value is the page's media box. - The bleed box defines the region to which the contents of the page should be clipped when output in a production environment. This may include any extra bleed area needed to accommodate the physical limitations of cutting, folding, and trimming equipment. The default value is the page's crop box. - The trim box defines the intended dimensions of the finished page after trimming. It may be smaller than the media box to allow for production related content, such as printing instructions, cut marks, or color bars. The default value is the page's crop box. - The art box defines the extent of the page's meaningful content (including potential white space) as intended by the page's creator. The default value is the page's crop box. - The user crop box defines a custom region to which the contents of the page are to be clipped (cropped) when displayed by PDFNet It must be fully contained within the e_crop box. The default value is the page's crop box.

Constant Value: 0 (0x00000000)

public static final int e_trim

The Constant e_trim.

Constant Value: 3 (0x00000003)

public static final int e_user_crop

The Constant e_user_crop.

Constant Value: 5 (0x00000005)

Public Constructors

public Page ()

Initialize a page using an existing low-level Cos/SDF page object.

Note: This constructor does not copy any data, but is instead the logical equivalent of a type cast.

Note: Because PDF::PDFDoc provides a complete high-level interface for Page creation and traversal this constructor is rarely used.

public Page (Obj page_dict)

Instantiates a new page from page dictionary

Parameters
page_dict page dictionary as Obj

Public Methods

public static Page __Create (long impl, Object ref)

public long __GetHandle ()

public static int addRotations (int r0, int r1)

Rotate r0 clockwise by r1

Parameters
r0 first rotation.
r1 second rotation.
Returns
  • rotation returns r0 + r1

public void annotInsert (int pos, Annot annot)

Adds an annotation at the specified location in a page's annotation array.

Parameters
pos - The location in the array to insert the object. The object is inserted before the specified location. The first element in an array has a pos of zero. If pos >= GetNumAnnots(), the method appends the annotation to the array.
annot - The annotation to add.

public void annotPushBack (Annot annot)

Adds an annotation to the end of a page's annotation array.

Parameters
annot - The annotation to prepend in a page's annotation array.

public void annotPushFront (Annot annot)

Adds an annotation to the beginning of a page's annotation array.

Parameters
annot - The annotation to append in a page's annotation array.

public void annotRemove (int index)

Removes the annoation at a given location.

Note: Removing the annotation invalidates any associated Annot object.

Parameters
index - A zero based index of the annotation to remove.

public void annotRemove (Annot annot)

Removes the given annotation from the page.

Note: Removing the annotation invalidates the given Annot object.

Parameters
annot the annotation to remove

public static int degreeToRotation (int r)

Convert a number that represents rotation in degrees to a rotation enum.

Parameters
r degree to convert to rotation. Valid numbers are multiples of 90.
Returns
  • one of four angles; e_0, e_90, e_180 or e_270. Returns e_0 if input is not a multiple 90.

public Obj findInheritedAttribute (String attrib)

Some of the page attributes are designated as inheritable. If such an attribute is omitted from a page object, its value is inherited from an ancestor node in the page tree. If the attribute is a required one, a value must be supplied in an ancestor node; if it is optional and no inherited value is specified, the default value should be used. The function walks up the page inhritance tree in search for specified attribute.

Parameters
attrib the inherited attribute to find
Returns
  • if the attribute was found return a pointer to the value. otherwise the function return NULL. Resources dictionary (Required; inheritable) MediaBox rectangle (Required; inheritable) CropBox rectangle (Optional; inheritable) Rotate integer (Optional; inheritable)

public void flattenField (Field field)

Flatten/Merge existing form field appearances with the page content and remove widget annotation. Form 'flattening' refers to the operation that changes active form fields into a static area that is part of the PDF document, just like the other text and images in the document. A completely flattened PDF form does not have any widget annotations or interactive fields.

Note: An alternative approach to set the field as read only is using Field.SetFlag(Field::e_read_only, true) method. Unlike Field.SetFlag(...), the result of FlattenField() operation can not be programatically reversed.

Parameters
field the field to flatten

public Annot getAnnot (int index)

Get the annotation on the page.

Parameters
index The index of the annotation to get on apage. The first annotation on a page has an index of zero.
Returns
  • Annotation object. If the index is out of range returned Annot object is not valid (i.e. annot.IsValid() returns false).

public Obj getAnnots ()

Returns a SDF/Cos array containing annotation dictionaries.

Returns
  • an array of annotation dictionaries representing annotations associated with the page or null if page dictionary is not specified.

public Rect getBox (int type)

Get the box specified page bounding box

Parameters
type The type of the page bounding box. Possible values are: e_media, e_crop, e_bleed, e_trim, and e_art. If the value for 'type' is e_crop, this call is equivalent to GetCropBox(). If the value for 'type' is e_media, this call is equivalent to GetMediaBox().
Returns
  • the box specified for the page object intersected with the media box.

public Obj getContents ()

Get the contents of current page.

Returns
  • NULL if page is empty, otherwise a single stream or an array of streams.

public Rect getCropBox ()

Get the crop box.

Note: this method is equivalent to GetBox(Page.e_crop)

Returns
  • the crop box for this page. The page dimensions are specified in user space coordinates. The crop box is the region of the page to display and print.

public Matrix2D getDefaultMatrix (boolean flip_y, int box_type, int rot_type)

Get the default matrix.

Parameters
flip_y this parameter can be used to mirror the page. if 'flip_y' is true the Y axis is not flipped and it is increasing, otherwise Y axis is decreasing.
box_type an optional parameter used to specify the page box/region that the matrix should map to. By default, the function transforms user space coordinates to cropped coordinates.
rot_type the rot_type
Returns
  • the matrix that transforms user space coordinates to rotated and cropped coordinates. The origin of this space is the bottom-left of the rotated, cropped page.

public Matrix2D getDefaultMatrix ()

Get the default matrix.

Returns
  • the matrix that transforms user space coordinates to rotated and cropped coordinates. The origin of this space is the bottom-left of the rotated, cropped page.

public int getIndex ()

Get the page index/number.

Returns
  • the Page number indication the position of this Page in document's page sequence. Document's page sequence is indexed from 1. Page number 0 means that the page is not part of document's page sequence or that the page is not valid.

public Rect getMediaBox ()

Get the media box.

Note: this method is equivalent to GetBox(Page::e_media)

Returns
  • the media box for this page. The page dimensions are specified in user space coordinates. The media box defines the boundaries of the physical medium on which the page is to be printed. It may include any extended area surrounding the finished page for bleed, printing marks, or other such purposes.

public int getNumAnnots ()

Get the number of annotations on a page. Widget annotations (form fields) are included in the count.

Returns
  • The number of annotations on a page.

public double getPageHeight ()

Get the crop box page height.

Returns
  • the height for the given page region/box taking into account page rotation attribute (i.e. /Rotate entry in page dictionary).

public double getPageHeight (int box_type)

Get the page height for the given page bounding box

Parameters
box_type the input bounding box type
Returns
  • the page height

public double getPageWidth (int box_type)

Get the page width for the given bounding box

Parameters
box_type given page bounding type
Returns
  • the page width

public double getPageWidth ()

Get the crop box page width.

Returns
  • the width for the given page region/box taking into account page rotation attribute (i.e. /Rotate entry in page dictionary).

public Obj getResourceDict ()

Get the resource dictionary of current page.

Returns
  • a pointer to the page resource dictionary.

public int getRotation ()

Get the rotation.

Returns
  • the rotation value for this page.

public Obj getSDFObj ()

Get the page dictionary.

Returns
  • the object to the underlying SDF/Cos object.

public Obj getThumb ()

Gets the object representing the Image thumbnail.

Note: If the page does not contain embedded thumbnail information, this method will return null.

public int[] getThumbInfo ()

Gets the associated thumbnail information.

Note: If the page does not contain embedded thumbnail information, this method will return null.

Returns
  • pixel buffer. In the returned buffer, the last two elements store the width and height of the returned thumbnail view. The leading elements store the actual pixels.

public Obj getTriggerAction (int trigger)

Get the Action associated with the selected Page Trigger event.

Parameters
trigger the type of trigger event to get
Returns
  • The Action Obj if present, otherwise NULL

public double getUserUnitSize ()

Get the UserUnit value for the page. A UserUnit is a positive number giving the size of default user space units, in multiples of 1/72 inch.

Returns
  • the UserUnit value for the page. If the key is not present in the page dictionary the default of 1.0 is returned.

public Rect getVisibleContentBox ()

The bounding box is defined as the smallest rectangle that includes all the visible content on the page.

Returns
  • the bounding box for this page. The page dimensions are specified in user space coordinates.

public boolean hasTransition ()

Tests whether this page has a transition.

Returns
  • true, if this page has a transition

public boolean isValid ()

Checks if current page is valid.

Returns
  • true if this is a valid (non-null) page, false otherwise. If the function returns false the underlying SDF/Cos object is null or is not valid.

public static int rotationToDegree (int r)

Convert a rotation to a number.

Parameters
r rotation to convert to number
Returns
  • one of four numbers; 0, 90, 180 or 270.

public void scale (double scale)

A utility method used to scale physical dimensions of the page including all page content.

Note: Unlike SetUserUnitSize(unit_size) which is only supported in PDF 1.6 (i.e. Acrobat 7) and above, page.Scale(sc) supports all PDF versions.

Parameters
scale A number greater than 0 which is used as a scale factor. For example, calling page.Scale(0.5) will reduce physical dimensions of the page to half its original size, whereas page.Scale(2) will double the physical dimensions of the page and will rescale all page content appropriately.

public void setBox (int type, Rect box)

Set the page bounding box specified by 'page_region' for this page.

Parameters
type The type of the page bounding box. Possible values are: e_media, e_crop, e_bleed, e_trim, and e_art.
box A rectangle specifying the coordinates to set for the box. The coordinates are specified in user space units.

public void setCropBox (Rect box)

Set the crop box for this page. The crop box is the region of the page to display and print.

Note: this method is equivalent to SetBox(Page.e_crop)

Parameters
box the new crop box for this page. The page dimensions are specified in user space coordinates. The crop box defines the region to which the contents of the page are to be clipped (cropped) when displayed or printed.

public void setMediaBox (Rect box)

Set the media box for this page.

Note: this method is equivalent to SetBox(Page::e_media)

Parameters
box the new media box for this page. The page dimensions are specified in user space coordinates. The media box defines the boundaries of the physical medium on which the page is to be printed. It may include any extended area surrounding the finished page for bleed, printing marks, or other such purposes.

public void setRotation (int rot_type)

Set the rotation value for this page.

Parameters
rot_type the new rotation

public void setUserUnitSize (double unit_size)

Set the UserUnit value for a page.

Note: This is a PDF 1.6 feature. See the implementation note 171 in PDF Reference for details.

Parameters
unit_size A positive number giving the size of default user space units, in multiples of 1/72 inch.

public static int subtractRotations (int r0, int r1)

Rotate r0 counter clockwise by r1.

Parameters
r0 first rotation.
r1 second rotation.
Returns
  • rotation returns r0 - r1