PdfPageTemplateElement

6 Jul 20261 minute to read

Represents a template element for creating and rendering header and footer content in a PDF document.

// Create a new document
let document: PdfDocument = new PdfDocument();
// Create a header template
let headerTemplate: PdfPageTemplateElement = new PdfPageTemplateElement({ width: 500, height: 50 });
// Get the graphics of the template
let graphics: PdfGraphics = headerTemplate.graphics;
// Draw content on header
graphics.drawString('Document Header', font, {x: 10, y: 10, width: 550, height: 30}, brush);
// Assign to document
document.template.top = {template: headerTemplate, alignment: PdfTemplateHorizontalAlignment.center};
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();

Properties

Get graphics PdfGraphics

Gets the graphics surface to draw template content.

// Create a new document
let document: PdfDocument = new PdfDocument();
// Create a header template
let headerTemplate: PdfPageTemplateElement = new PdfPageTemplateElement({ width: 500, height: 50 });
// Get the graphics of the template
let graphics: PdfGraphics = headerTemplate.graphics;
// Draw content on header
graphics.drawString('Document Header', font, {x: 10, y: 10, width: 550, height: 30}, brush);
// Assign to document
document.template.top = {template: headerTemplate, alignment: PdfTemplateHorizontalAlignment.center};
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();