MCPcopy Create free account
hub / github.com/docling-project/docling-parse / get_annotations

Method get_annotations

docling_parse/pdf_parser.py:869–899  ·  view source on GitHub ↗

Get document annotations including form fields, language, metadata, and TOC. Returns: Optional[PdfAnnotations]: Annotations object with form, language, meta_xml, and table_of_contents fields. None if document is not loaded or no annotations.

(self)

Source from the content-addressed store, hash-verified

867 return result
868
869 def get_annotations(self) -> PdfAnnotations | None:
870 """Get document annotations including form fields, language, metadata, and TOC.
871
872 Returns:
873 Optional[PdfAnnotations]: Annotations object with form, language, meta_xml,
874 and table_of_contents fields. None if document is not loaded or no annotations.
875 """
876 if self._annotations is not None:
877 return self._annotations
878
879 if self.is_loaded():
880 annots_dict = self._parser.get_annotations(key=self._key)
881
882 if annots_dict is None:
883 return self._annotations
884
885 # Convert table_of_contents list of dicts to PdfTocEntry objects if present
886 toc_entries = None
887 if annots_dict.get("table_of_contents"):
888 toc_entries = self._to_pdf_toc_entry(annots_dict["table_of_contents"])
889
890 self._annotations = PdfAnnotations(
891 form=annots_dict.get("form"),
892 language=annots_dict.get("language"),
893 meta_xml=annots_dict.get("meta_xml"),
894 table_of_contents=toc_entries,
895 )
896
897 return self._annotations
898 else:
899 raise RuntimeError("This document is not loaded.")
900
901 def get_page(
902 self,

Callers

nothing calls this directly

Calls 4

is_loadedMethod · 0.95
_to_pdf_toc_entryMethod · 0.95
PdfAnnotationsClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected