Extract annotations from document page

get_annotations(page_index) returns the annotations of one page (or slide) only. Page indexes start at 0.

Extract annotations from a specific page

from groupdocs.parser import Parser

with Parser("./reviewed.pdf") as parser:
    # Extract annotations from the first page (page indexes start at 0)
    annotations = parser.get_annotations(0)

    if annotations is None:
        print("Annotation extraction isn't supported for this format")
    else:
        print("Page 1: %d annotations" % len(annotations))
        for annotation in annotations:
            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:

from groupdocs.parser import Parser

with Parser("./reviewed.pdf") as parser:
    if not parser.features.annotations:
        print("Annotation extraction isn't supported for this format")
    else:
        page_count = parser.get_document_info().page_count
        for page_index in range(page_count):
            annotations = parser.get_annotations(page_index)
            print("Page %d of %d: %d annotations" % (page_index + 1, page_count, len(annotations)))
            for annotation in annotations:
                print("  %s: %s" % (annotation.author_name or "(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.
Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.