PdfSection
6 Jul 20262 minutes to read
Represents a PDF section, a set of pages with similar page settings.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a new section to the document
let section: PdfSection = document.addSection();
// Add a page to the section
let page: PdfPage = section.addPage();
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Properties
Get template PdfDocumentTemplate
Gets the template configuration for section-level headers and footers.
// Create a new document
const document: PdfDocument = new PdfDocument();
// Initialize a standard font for drawing
const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 12);
// Initialize a brush for text drawing
const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 });
// Create a new section in the document
const section: PdfSection = document.addSection();
// Add a page to the created section
section.addPage();
// Access the section template
const template: PdfDocumentTemplate = section.template;
// Create a section-specific page template
const sectionTemplate: PdfPageTemplateElement = new PdfPageTemplateElement({ width: 500, height: 50 });
// Draw header text into the section template
template.graphics.drawString('Section Header', font, { x: 10, y: 10, width: 150, height: 30 }, brush);
// Assign the section template to the section's top slot
template.top = { template: sectionTemplate, alignment: PdfTemplateHorizontalAlignment.center };
// Save document
document.save('Output.pdf');
// Destroy the document
document.destroy();Methods
addPage
Creates a new page and adds it to the collection.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a new section to the document
let section: PdfSection = document.addSection();
// Add a page to the section
let page: PdfPage = section.addPage();
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Returns PdfPage