[]
        
(Showing Draft Content)

PdfPage

DsPdfJS API v9.1.0


DsPdfJS API / PdfPage

Class: PdfPage

Represents a page in a PdfDocument.

Extends

Accessors

annotations

Get Signature

get annotations(): AnnotationCollection

Gets the list of annotations associated with the PdfPage.

Returns

AnnotationCollection


context

Get Signature

get context(): PdfContext

Gets a PdfContext for the current page.

Returns

PdfContext


cropBox

Get Signature

get cropBox(): Rect | null

Gets or sets a rectangle, in points, defining the visible region of default user space. When the PdfPage is displayed or printed, its contents are to be clipped (cropped) to this rectangle and then imposed on the output medium in some implementation-defined manner. Default value is @mediaBox.

Returns

Rect | null

Set Signature

set cropBox(value): void

Gets or sets a rectangle, in points, defining the visible region of default user space. When the PdfPage is displayed or printed, its contents are to be clipped (cropped) to this rectangle and then imposed on the output medium in some implementation-defined manner. Default value is @mediaBox.

Parameters
value

Rect | null

Returns

void


document

Get Signature

get document(): PdfDocument | null

Gets the owner PdfDocument or null, if the PdfPage is orphan.

Returns

PdfDocument | null


height

Get Signature

get height(): number

The height of the PdfPage, in points.

Returns

number


id

Get Signature

get id(): number

Gets the reference to the object.

Returns

number

Inherited from

ObjectBase.id


index

Get Signature

get index(): number

Gets the index of the PdfPage in the owner PdfPageCollection, or -1.

Returns

number


mediaBox

Get Signature

get mediaBox(): Rect

Gets or sets the bounds of the PdfPage in points.

Returns

Rect

Set Signature

set mediaBox(value): void

Gets or sets the bounds of the PdfPage in points.

Parameters
value

Rect

Returns

void


om

Get Signature

get om(): ObjectManager

Gets the owner ObjectManager instance.

Returns

ObjectManager

Inherited from

ObjectBase.om


rotation

Get Signature

get rotation(): number

Gets or sets the number of degrees by which the PdfPage should be rotated clockwise when displayed or printed. The value is a multiple of 90.

Returns

number

Set Signature

set rotation(degrees): void

Gets or sets the number of degrees by which the PdfPage should be rotated clockwise when displayed or printed. The value is a multiple of 90.

Parameters
degrees

number

Returns

void


transitionDuration

Get Signature

get transitionDuration(): number | null

Gets or sets the PdfPage's display duration (also called its advance timing): the maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page. The value of null means that the viewer shall not advance automatically.

Returns

number | null

Set Signature

set transitionDuration(value): void

Gets or sets the PdfPage's display duration (also called its advance timing): the maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page. The value of null means that the viewer shall not advance automatically.

Parameters
value

number | null

Returns

void


width

Get Signature

get width(): number

The width of the PdfPage, in points.

Returns

number

Methods

adjustPoint()

adjustPoint(value, fromBottomLeft?, deviceDpiX?, deviceDpiY?): Point

Converts specified visual coordinates (usually in the coordinate system with the origin in the top left corner of the PdfPage and the Y axis going down, see 'fromBottomLeft') to coordinates that take into account PdfPage#rotation, PdfPage#cropBox and PdfPage#mediaBox (if 'CropBox' is not specified) values. This method should be used when positioning annotations or destinations on a page. Do not use this method when drawing on 'context'.

Parameters

value

Point

The Point to adjust.

fromBottomLeft?

boolean = false

If true, the source coordinates' origin is in the bottom left corner of the page with Y axis going up (by default it is in the top left corner with Y axis going down).

deviceDpiX?

number = 72

The horizontal device resolution.

deviceDpiY?

number = 72

The vertical device resolution.

Returns

Point


adjustQuadrilateral()

adjustQuadrilateral(value, fromBottomLeft?, deviceDpiX?, deviceDpiY?): Quadrilateral

Converts specified visual coordinates (usually in the coordinate system with the origin in the top left corner of the PdfPage and the Y axis going down, see 'fromBottomLeft') to coordinates that take into account PdfPage#rotation, PdfPage#cropBox and PdfPage#mediaBox (if 'CropBox' is not specified) values. This method should be used when positioning annotations or destinations on a page. Do not use this method when drawing on 'context'.

Parameters

value

Quadrilateral

The Quadrilateral to adjust.

fromBottomLeft?

boolean = false

If true, the source coordinates' origin is in the bottom left corner of the page with Y axis going up (by default it is in the top left corner with Y axis going down).

deviceDpiX?

number = 72

The horizontal device resolution.

deviceDpiY?

number = 72

The vertical device resolution.

Returns

Quadrilateral


adjustRect()

adjustRect(value, fromBottomLeft?, deviceDpiX?, deviceDpiY?): Rect

Converts specified visual coordinates (usually in the coordinate system with the origin in the top left corner of the PdfPage and the Y axis going down, see 'fromBottomLeft') to coordinates that take into account PdfPage#rotation, PdfPage#cropBox and PdfPage#mediaBox (if 'CropBox' is not specified) values. This method should be used when positioning annotations or destinations on a page. Do not use this method when drawing on 'context'.

Parameters

value

Rect

The Rect to adjust.

fromBottomLeft?

boolean = false

If true, the source coordinates' origin is in the bottom left corner of the page with Y axis going up (by default it is in the top left corner with Y axis going down).

deviceDpiX?

number = 72

The horizontal device resolution.

deviceDpiY?

number = 72

The vertical device resolution.

Returns

Rect


deleteText()

Call Signature

deleteText(findTextParams, deleteTextMode): void

Deletes a specified text from the PdfPage.

Parameters
findTextParams

FindTextParams

The text to search for.

deleteTextMode

DeleteTextMode

The text delete mode.

Returns

void

Call Signature

deleteText(textMapFragment, deleteTextMode): void

Deletes the specified text range from the PdfPage.

Parameters
textMapFragment

TextMapFragment

The text range.

deleteTextMode

DeleteTextMode

The text delete mode.

Returns

void


draw()

Call Signature

draw(context, x, y, width, height, options?): void

Draws the PdfPage on the given context into the specified rectangle.

Parameters
context

DrawingContext

The target drawing context.

x

number

The X coordinate of the destination rectangle.

y

number

The Y coordinate of the destination rectangle.

width

number

The width of the destination rectangle.

height

number

The height of the destination rectangle.

options?

DrawPdfPageOptions

The options for the drawing the PdfPage.

Returns

void

Example
const page = doc.pages.getAt(0);
const svgCtx = new SvgContext(300, 500);
page.draw(svgCtx, 0, 0, 300, 500, {
    viewStateMode: ViewStateMode.Print
});
const svgDoc = svgCtx.toSvgDocument();

Call Signature

draw(context, bounds, options?): void

Draws the PdfPage on the given context into the specified rectangle.

Parameters
context

DrawingContext

The target drawing context.

bounds

Bounds

The destination rectangle.

options?

DrawPdfPageOptions

The options for the drawing the PdfPage.

Returns

void


free()

free(): void

Detaches the object from the ObjectManager and deallocates its memory, if possible.

Returns

void

Inherited from

ObjectBase.free


getRenderSize()

getRenderSize(deviceDpiX?, deviceDpiY?): Size

Gets the size of the PdfPage on a device with specified horizontal and vertical resolutions.

Parameters

deviceDpiX?

number = 72

The horizontal device resolution.

deviceDpiY?

number = 72

The vertical device resolution.

Returns

Size


getText()

getText(): string

Retrieves all text on the PdfPage.

Returns

string


rebind()

rebind(omTo): void

Rebinds the object from the current ObjectManager to the specified one.

Parameters

omTo

ObjectManager

The new ObjectManager for the object.

Returns

void

Inherited from

ObjectBase.rebind


replaceText()

Call Signature

replaceText(findTextParams, newText, font?, fontSize?): void

Replaces a specified text on the PdfPage.

Note that the results may be affected by the current value of the PdfDocument#recognitionAlgorithm property.

Parameters
findTextParams

FindTextParams

The text to search for.

newText

string

The replacement text.

font?

The font to use on 'newText', if null the current font will be used.

Font | null

fontSize?

The font size to use on 'newText', if null the current font size will be used.

number | null

Returns

void

Call Signature

replaceText(textMapFragment, newText, font?, fontSize?): void

Replaces a specified text on the PdfPage.

Note that the results may be affected by the current value of the PdfDocument#recognitionAlgorithm property.

Parameters
textMapFragment

TextMapFragment

The text range.

newText

string

The replacement text.

font?

The font to use on 'newText', if null the current font will be used.

Font | null

fontSize?

The font size to use on 'newText', if null the current font size will be used.

number | null

Returns

void


saveAsPng()

saveAsPng(options?): Uint8Array

Saves the PdfPage to a byte array in PNG format.

Parameters

options?

SaveAsImageOptions

The options for page export.

Returns

Uint8Array

The resulting binary data in PNG format.

Example

const doc = PdfDocument.load(data);
const page = doc.pages.getAt(0);
const imageBytes = page.saveAsPng({ backColor: "GhostWhite" });

saveAsPngImage()

saveAsPngImage(options?): Image

Saves the PdfPage to an Image in PNG format.

Parameters

options?

SaveAsImageOptions

The options for page export.

Returns

Image

The resulting Image object.


saveAsSvg()

saveAsSvg(options?): Uint8Array

Saves the PdfPage to a byte array in SVG format.

Parameters

options?

SaveAsImageOptions

The options for page export.

Returns

Uint8Array

The resulting data in UTF-8 encoded SVG format.


saveAsSvgDocument()

saveAsSvgDocument(options?): SvgDocument

Saves the PdfPage as an SvgDocument.

Parameters

options?

SaveAsImageOptions

The options for page export.

Returns

SvgDocument

The resulting SvgDocument object.


saveAsSvgGz()

saveAsSvgGz(options?): Uint8Array

Saves the PdfPage to a byte array in SVG.GZ format.

Parameters

options?

SaveAsImageOptions

The options for page export.

Returns

Uint8Array

The resulting binary data in SVG.GZ format.