PdfAnnotationCollection class

Typed collection of the annotations already present on a page.

It is gap §2.2 item 3 of the roadmap: there were classes to create annotations (PdfAnnot), but none to list, change, remove or flatten the ones that came from the file. The collection works over the /Annots array of the page and over the dictionaries resolved by the PdfObjectStore, without duplicating an object.

final document = PdfDocument.parseFromBytes(bytes);
final annotations = PdfAnnotationCollection.onPage(document, 1);
for (final annotation in annotations.annotations) {
  print('${annotation.subtype} ${annotation.rect}');
}
annotations.annotations.first.contents = 'Revisar';
annotations.remove(annotations.annotations.last);
final bytes = await document.save();

Known limits

  • the two-way coherence with /Popup, /Parent and /IRT planned for F5 is not maintained yet: removing an annotation does not remove its popup;
  • /P is not rewritten, because the annotation stays on the same page;
  • there is no appearance generation. flatten draws the appearance that already exists and refuses the annotation that has none.

Constructors

PdfAnnotationCollection(PdfPage page, {PdfObjectStore? store, PdfLoadedObjectMutator? mutator, PdfAcroFormAccess? acroForm})
Creates the collection of the annotations of page.
factory
PdfAnnotationCollection.onPage(PdfDocument document, int pageIndex)
Creates the collection of the page with index pageIndex (zero based).
factory

Properties

acroForm → PdfAcroFormAccess
The single path for changing the /AcroForm.
final
annotations → List<PdfAnnotationView>
The annotations of the page, in the order of the /Annots array.
no setter
document → PdfDocument
The document that owns the page.
final
hashCode → int
The hash code for this object.
no setterinherited
length → int
Number of annotations.
no setter
mutator → PdfLoadedObjectMutator
The materializer used in the changes.
final
page → PdfPage
The page whose annotations the collection sees.
final
painter → PdfAppearancePainter
The appearance painter of this page, created on demand.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
store → PdfObjectStore
The object resolution, with a fallback to the source parser.
final
transformer → PdfCoordinateTransformer
Coordinate converter of this page.
final
warnings → List<String>
What the collection could not do, in the order it happened.
no setter

Methods

byName(String name) → PdfAnnotationView?
The annotation whose /NM equals name, or null.
flatten(PdfAnnotationView view) → bool
Flattens view: draws its normal appearance on the page and removes it.
flattenAll() → int
Flattens every annotation that has an appearance.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(PdfAnnotationView view) → bool
Removes view from the page.
toString() → String
A string representation of this object.
inherited
whereSubtype(String subtype) → Iterable<PdfAnnotationView>
The annotations of a specific /Subtype, for example /Link.

Operators

operator ==(Object other) → bool
The equality operator.
inherited
operator [](int index) → PdfAnnotationView
The annotation at index index.