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
Page 1: 2 annotations
[Text] Check the 2,400 kg against last season's sell-through before we sign.
[Highlight] Release date works for the Q4 cash forecast.
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
Page 1 of 2: 2 annotations
Lena Park: Check the 2,400 kg against last season's sell-through before we sign.
Amara Osei: Release date works for the Q4 cash forecast.
Page 2 of 2: 2 annotations
Amara Osei: Ask Northwind for the green coffee index they will use.
Lena Park: Dock 2 is reserved for these two mornings.