PdfTemplateLayerMode

6 Jul 20261 minute to read

Public enum to define template layer rendering mode.

// Create new document
let document: PdfDocument = new PdfDocument();
// Create a header template
let headerTemplate: PdfPageTemplateElement = new PdfPageTemplateElement({width: 595, height: 50});
// Set template to render as background
headerTemplate.templateLayerMode = PdfTemplateLayerMode.background;
// Draw content on header
headerTemplate.graphics.drawString('Header', font, {x: 10, y: 10, width: 575, height: 30}, brush);
// Assign to the document template along with the template layer rendering mode
document.template.top = {template: headerTemplate, templateLayerMode: PdfTemplateLayerMode.background, alignment: PdfHorizontalAlignment.center};
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
  • background - Specifies that the template renders behind page content (background layer).
  • foreground - Specifies that the template renders above page content (foreground layer).