PdfPage

6 Jul 20264 minutes to read

Represents a page loaded from the PDF document.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access first page
let page: PdfPage = document.getPage(0);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();

Properties

Get _contentTemplate PdfTemplate

Gets the page’s combined content as a reusable template.

Get _origin number[]

Gets the origin coordinates derived from the MediaBox.

Get annotations PdfAnnotationCollection

Gets the collection of the page’s annotations (Read only).

Get cropBox number[]

Gets the bounds that define the area intended for display or printing in the PDF viewer application (Read only).

Get graphics PdfGraphics

Gets the graphics of the page (Read only).

Get mediaBox number[]

Gets the size that specify the width and height of the page (Read only).

Get orientation PdfPageOrientation

Gets the orientation of the page (Read only).

Get rotation PdfRotationAngle

Gets the rotation angle of the page (Read only).

Set rotation void

Sets the rotation angle of the PDF page

Parameter Type Description
value PdfRotationAngle Rotation angle.

Get size Size

Gets the size of the page (Read only).

Get tabOrder PdfFormFieldsTabOrder

Gets the tab order of a PDF form field.

Set tabOrder void

Sets the tab order of a PDF form field.

Parameter Type Description
value PdfFormFieldsTabOrder Tab order.

Methods

drawTextElement

Draws a text element on the page at a given location.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the first page of the document
let page: PdfPage = document.getPage(0);
// Create a text element
let element: PdfTextElement = {
    text: 'Hello world drawn using a point location.',
    font: document.embedFont(PdfFontFamily.helvetica, 12, PdfFontStyle.regular),
    brush: new PdfBrush({ r: 0, g: 0, b: 0 })
};
// Draw the text element using a specific point
const result = page.drawTextElement(element, { x: 50, y: 100 });
// Save the PDF document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
element PdfTextElement The text element to draw.
location Point The location where the text element should be drawn.

Returns PdfLayoutResult

drawTextElement

Draws a text element inside a rectangle on the page.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the first page of the document
let page: PdfPage = document.getPage(0);
// Create a text element
let element: PdfTextElement = {
    text: 'Hello world drawn inside rectangle bounds.',
    font: document.embedFont(PdfFontFamily.helvetica, 12, PdfFontStyle.regular),
    brush: new PdfBrush({ r: 0, g: 0, b: 0 })
};
// Define the rectangle bounds
let rect: Rectangle = { x: 10, y: 20, width: 200, height: 50 };
// Draw the text element inside rectangle bounds
const result = page.drawTextElement(element, rect);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
element PdfTextElement The text element to draw.
bounds Rectangle The bounds within which the text element should be drawn.

Returns PdfLayoutResult