get_annotations(page_index) returns the annotations of one page (or slide) only. Page indexes start at 0.
Extract annotations from a specific page
fromgroupdocs.parserimportParserwithParser("./reviewed.pdf")asparser:# Extract annotations from the first page (page indexes start at 0)annotations=parser.get_annotations(0)ifannotationsisNone:print("Annotation extraction isn't supported for this format")else:print("Page 1: %d annotations"%len(annotations))forannotationinannotations:print(" [%s] %s"%(annotation.annotation_type,annotation.value))
The following sample file is used in this example: reviewed.pdf
Expected behavior: For the sample, prints:
Page 1: 2 annotations
[Text] Approve the hero crop before the print run.
[Link] Aurora Visuals portfolio
Extract annotations page by page
Use get_document_info().page_count to walk every page:
fromgroupdocs.parserimportParserwithParser("./reviewed.pdf")asparser:ifnotparser.features.annotations:print("Annotation extraction isn't supported for this format")else:page_count=parser.get_document_info().page_countforpage_indexinrange(page_count):annotations=parser.get_annotations(page_index)print("Page %d of %d: %d annotations"%(page_index+1,page_count,len(annotations)))forannotationinannotations:print(" %s: %s"%(annotation.author_nameor"(no author)",annotation.value))
The following sample file is used in this example: reviewed.pdf
Expected behavior: For the two-page sample, prints:
Page 1 of 2: 2 annotations
Tomas Reyes: Approve the hero crop before the print run.
(no author): Aurora Visuals portfolio
Page 2 of 2: 0 annotations
Notes
A page without annotations gives an empty list, not None.
Every AnnotationItem also carries its own page_index, so get_annotations() followed by grouping on page_index gives the same result in one call.