distinctPages static method

List<PdfPage> distinctPages(
  1. PdfDocument document
)

The distinct pages of document, in document order.

A loaded document registers each page twice in pdfPageList.pages: once by the PdfPage constructor and once by the parser's mergeDocument. Until the page collection from phase F3 exists, stamping directly over the list would draw twice on the same page and ignore half the document.

Implementation

static List<PdfPage> distinctPages(PdfDocument document) {
  final seen = <PdfPage>[];
  for (final page in document.pdfPageList.pages) {
    if (seen.any((e) => identical(e, page))) continue;
    seen.add(page);
  }
  return seen;
}