Pdf Component - PdfPage
18 Nov 20267 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 actions PdfPageActions
Gets the actions associated with the page events.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
let page: PdfPage = document.addPage();
// Get the page actions
let actions: PdfPageActions = page.actions;
// Create and assign an action to the page open event
let action: PdfJavaScriptAction = new PdfJavaScriptAction('app.alert("Page opened");');
actions.open = action;
// Save and destroy the document
document.save('output.pdf');
document.destroy();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
createTemplate
Generates a reusable template from the current PDF page.
Returns PdfTemplate
drawShapeElement
Draws a shape element on the page and paginates it to the following pages when it overflows the page height.
The position and size of the shape are taken from the shape geometry. Content wider than the page is clipped
to the page margin, and content taller than the page is continued on the next pages.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page
let page: PdfPage = document.addPage();
// Create a shape element
let element: PdfShapeElement = {
shape: {
type: PdfShapeType.Rectangle,
bounds: { x: 20, y: 20, width: 100, height: 1000 }
},
brush: new PdfBrush({ r: 165, g: 42, b: 42 }),
layoutFormat: { layoutType: PdfLayoutType.paginate, breakType: PdfLayoutBreakType.fitPage }
};
// Draw the shape element with pagination
let result: PdfLayoutResult = page.drawShapeElement(element);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| element | PdfShapeElement |
The shape element to draw. |
Returns PdfLayoutResult
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