fields property

List<PdfAutomaticField> get fields

Gets or sets the automatic fields(like page number, page count and etc.,)

//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 footer with specific bounds
PdfPageTemplateElement footer =
    PdfPageTemplateElement(const Rect.fromLTWH(0, 0, 515, 50));
//Create the page number field
PdfPageNumberField pageNumber = PdfPageNumberField(
    font: PdfStandardFont(PdfFontFamily.timesRoman, 19),
    brush: PdfSolidBrush(PdfColor(0, 0, 0)));
//Sets the number style for page number
pageNumber.numberStyle = PdfNumberStyle.upperRoman;
//Create the composite field
PdfCompositeField compositeField = PdfCompositeField(
    font: PdfStandardFont(PdfFontFamily.timesRoman, 19),
    brush: PdfSolidBrush(PdfColor(0, 0, 0)));
//Set text to composite field.
compositeField.text = 'Page {0}';
//Sets page number field to composite fields
compositeField.fields = <PdfAutomaticField>[pageNumber];
//Set bounds to composite field.
compositeField.bounds = footer.bounds;
//Add the composite field in footer
compositeField.draw(footer.graphics,
    Offset(290, 50 - PdfStandardFont(PdfFontFamily.timesRoman, 19).height));
//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

List<PdfAutomaticField> get fields {
  _fields ??= <PdfAutomaticField>[];
  return _fields!;
}
set fields (List<PdfAutomaticField> value)

Implementation

set fields(List<PdfAutomaticField> value) {
  _fields = value;
}