PdfPageTemplateElement constructor

PdfPageTemplateElement(
  1. Rect bounds, [
  2. PdfPage? page
])

Initializes a new instance of the PdfPageTemplateElement class.

//Create a new pdf document
PdfDocument document = PdfDocument();
//Add the pages to the document
for (int i = 1; i <= 5; i++) {
  document.pages.add().graphics.drawString(
      'page$i', PdfStandardFont(PdfFontFamily.timesRoman, 11),
      bounds: Rect.fromLTWH(250, 0, 615, 100));
}
//Create the header with specific bounds
PdfPageTemplateElement header = PdfPageTemplateElement(
    Rect.fromLTWH(0, 0, document.pages[0].getClientSize().width, 300));
header.graphics.drawString(
    'Header', PdfStandardFont(PdfFontFamily.helvetica, 14),
    brush: PdfBrushes.black);
//Add the header at top of the document
document.template.top = header;
//Create the footer with specific bounds
PdfPageTemplateElement footer = PdfPageTemplateElement(
    Rect.fromLTWH(0, 0, document.pages[0].getClientSize().width, 50));
header.graphics.drawString(
    'Footer', PdfStandardFont(PdfFontFamily.helvetica, 11),
    brush: PdfBrushes.black);
//Add the footer at the bottom of the document
document.template.bottom = footer;
//Save the document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

PdfPageTemplateElement(Rect bounds, [PdfPage? page]) {
  _helper = PdfPageTemplateElementHelper(this);
  x = bounds.left;
  y = bounds.top;
  _helper._pdfTemplate = PdfTemplate(bounds.width, bounds.height);
  if (page != null) {
    graphics.colorSpace = PdfPageHelper.getHelper(page).document!.colorSpace;
  }
}