Class: Page

PDFNet. Page


new Page()

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.

Methods


<static> addRotations(r0, r1)

Rotate r0 clockwise by r1

Parameters:
Name Type Description
r0 number/enum
PDFNet.Page.Rotate = {
	e_0 : 0
	e_90 : 1
	e_180 : 2
	e_270 : 3
}

first rotation.

r1 number/enum
PDFNet.Page.Rotate = {
	e_0 : 0
	e_90 : 1
	e_180 : 2
	e_270 : 3
}

second rotation.

Returns:

A promise that resolves to returns r0 + r1

Type
number
Example
Return value enum:
<pre>
PDFNet.Page.Rotate = {
	e_0 : 0
	e_90 : 1
	e_180 : 2
	e_270 : 3
}
</pre>

<static> create(page_dict)

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

Parameters:
Name Type Description
page_dict PDFNet.Obj

a low-level (SDF/Cos) page dictionary.

Returns:

A promise that resolves to an object of type: "Page"

Type
PDFNet.Page

<static> degreeToRotation(r)

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

Parameters:
Name Type Description
r number

degree to convert to rotation. Valid numbers are multiples of 90.

Returns:

A promise that resolves to one of four angles; e_0, e_90, e_180 or e_270. Returns e_0 if input is not a multiple 90.

Type
number
Example
Return value enum:
<pre>
PDFNet.Page.Rotate = {
	e_0 : 0
	e_90 : 1
	e_180 : 2
	e_270 : 3
}
</pre>

<static> rotationToDegree(r)

Convert a rotation to a number.

Parameters:
Name Type Description
r number/enum
PDFNet.Page.Rotate = {
	e_0 : 0
	e_90 : 1
	e_180 : 2
	e_270 : 3
}

rotation to convert to number

Returns:

A promise that resolves to one of four numbers; 0, 90, 180 or 270.

Type
number

<static> subtractRotations(r0, r1)

Rotate r0 counter clockwise by r1.

Parameters:
Name Type Description
r0 number/enum
PDFNet.Page.Rotate = {
	e_0 : 0
	e_90 : 1
	e_180 : 2
	e_270 : 3
}

first rotation.

r1 number/enum
PDFNet.Page.Rotate = {
	e_0 : 0
	e_90 : 1
	e_180 : 2
	e_270 : 3
}

second rotation.

Returns:

A promise that resolves to returns r0 r1

Type
number
Example
Return value enum:
<pre>
PDFNet.Page.Rotate = {
	e_0 : 0
	e_90 : 1
	e_180 : 2
	e_270 : 3
}
</pre>

annotInsert(pos, annot)

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

Parameters:
Name Type Description
pos number

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 PDFNet.Annot

The annotation to add.


annotPushBack(annot)

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

Parameters:
Name Type Description
annot PDFNet.Annot

The annotation to prepend in a page's annotation array.


annotPushFront(annot)

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

Parameters:
Name Type Description
annot PDFNet.Annot

The annotation to append in a page's annotation array.


annotRemove(annot)

Removes the given annotation from the page.

Parameters:
Name Type Description
annot PDFNet.Annot

The annotation to remove.


annotRemoveByIndex(index)

Removes the annotation at a given location.

Parameters:
Name Type Description
index number

A zero based index of the annotation to remove.


copy()

Copy Constructor

Returns:

A promise that resolves to an object of type: "Page"

Type
PDFNet.Page

findInheritedAttribute(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 inheritance tree in search for specified attribute.

Parameters:
Name Type Description
attrib string

A string representing the attribute to search for.

Returns:

A promise that resolves to 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)

Type
PDFNet.Obj

flattenField(field_to_flatten)

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.

Parameters:
Name Type Description
field_to_flatten PDFNet.field

field to flatten


getAnnot(index)

Returns the annotation on the page.

Parameters:
Name Type Description
index number

The index of the annotation to get on a page. The first annotation on a page has an index of zero.

Returns:

A promise that resolves to annotation object. If the index is out of range returned Annot object is not valid (i.e. annot.IsValid() returns false).

Type
PDFNet.Annot

getAnnots()

Returns SDF/Cos array containing annotation dictionaries. See Section 8.4 in the PDF Reference for a description of the annotation array.

Returns:

A promise that resolves to an array of annotation dictionaries representing annotations associated with the page or NULL if page dictionary is not specified.

Type
PDFNet.Obj

getBox(type)

Parameters:
Name Type Description
type number/enum
PDFNet.Page.Box = {
	e_media : 0
	e_crop : 1
	e_bleed : 2
	e_trim : 3
	e_art : 4
}

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:

A promise that resolves to the box specified for the page object intersected with the media box.

Type
PDFNet.rect

getContents()

Returns:

A promise that resolves to nULL if page is empty, otherwise a single stream or an array of streams.

Type
PDFNet.Obj

getCropBox()

Returns:

A promise that resolves to 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.

Type
PDFNet.rect

getDefaultMatrix(flip_y, box_type, angle)

Parameters:
Name Type Description
flip_y boolean

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 number/enum
PDFNet.Page.Box = {
	e_media : 0
	e_crop : 1
	e_bleed : 2
	e_trim : 3
	e_art : 4
}

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.

angle number/enum
PDFNet.Page.Rotate = {
	e_0 : 0
	e_90 : 1
	e_180 : 2
	e_270 : 3
}

an optional parameter used to specify page rotation in addition to the rotation specified in the page dictionary. This parameter is usually used to rotate the page without modifying the document itself.

Returns:

A promise that resolves to 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.

Type
PDFNet.matrix2d

getIndex()

Returns:

A promise that resolves to 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.

Type
number

getMediaBox()

Returns:

A promise that resolves to 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.

Type
PDFNet.rect

getNumAnnots()

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

Returns:

A promise that resolves to the number of annotations on a page.

Type
number

getPageHeight(box_type)

Parameters:
Name Type Description
box_type number/enum
PDFNet.Page.Box = {
	e_media : 0
	e_crop : 1
	e_bleed : 2
	e_trim : 3
	e_art : 4
}

indicates the page box/region to query for height.

Returns:

A promise that resolves to the height for the given page region/box taking into account page rotation attribute (i.e. /Rotate entry in page dictionary).

Type
number

getPageWidth(box_type)

Parameters:
Name Type Description
box_type number/enum
PDFNet.Page.Box = {
	e_media : 0
	e_crop : 1
	e_bleed : 2
	e_trim : 3
	e_art : 4
}

indicates the page box/region to query for width.

Returns:

A promise that resolves to the width for the given page region/box taking into account page rotation attribute (i.e. /Rotate entry in page dictionary).

Type
number

getResourceDict()

Returns:

A promise that resolves to a pointer to the page resource dictionary.

Type
PDFNet.Obj

getRotation()

Returns:

A promise that resolves to the rotation value for this page.

Type
number
Example
Return value enum:
<pre>
PDFNet.Page.Rotate = {
	e_0 : 0
	e_90 : 1
	e_180 : 2
	e_270 : 3
}
</pre>

getSDFObj()

Returns the page dictionary.

Returns:

A promise that resolves to the object to the underlying SDF/Cos object.

Type
PDFNet.Obj

getThumb()

Returns:

A promise that resolves to object representing the Image thumbnail.

Type
PDFNet.Obj

getTriggerAction(trigger)

Get the Action associated with the selected Page Trigger event.

Parameters:
Name Type Description
trigger number/enum
PDFNet.Page.EventType = {
	e_action_trigger_page_open : 11
	e_action_trigger_page_close : 12
}

the type of trigger event to get

Returns:

A promise that resolves to the Action Obj if present, otherwise NULL

Type
PDFNet.Obj

getUserUnitSize()

Returns 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:

A promise that resolves to the UserUnit value for the page. If the key is not present in the page dictionary the default of 1.0 is returned.

Type
number

getVisibleContentBox()

Returns:

A promise that resolves to the bounding box for this page. The page dimensions are specified in user space coordinates.

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

Type
PDFNet.rect

hasTransition()

tests whether this page has a transition.

Returns:

A promise that resolves to an unknown type


isValid()

Returns:

A promise that resolves to 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.

Type
boolean

scale(scale)

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

Parameters:
Name Type Description
scale number

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.


setBox(type, box)

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

Parameters:
Name Type Description
type number/enum
PDFNet.Page.Box = {
	e_media : 0
	e_crop : 1
	e_bleed : 2
	e_trim : 3
	e_art : 4
}

The type of the page bounding box. Possible values are: e_media, e_crop, e_bleed, e_trim, and e_art.

box PDFNet.rect

A rectangle specifying the coordinates to set for the box. The coordinates are specified in user space units.


setCropBox(box)

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

Parameters:
Name Type Description
box PDFNet.rect

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.


setMediaBox(box)

Sets the media box for this page.

Parameters:
Name Type Description
box PDFNet.rect

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.


setRotation(angle)

Sets the rotation value for this page.

Parameters:
Name Type Description
angle number/enum
PDFNet.Page.Rotate = {
	e_0 : 0
	e_90 : 1
	e_180 : 2
	e_270 : 3
}

Rotation value to be set for a given page. Must be one of the Page::Rotate values.


setUserUnitSize(unit_size)

Sets the UserUnit value for a page.

Parameters:
Name Type Description
unit_size number

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