Skip to main content

PdfSpace Objects

class PdfSpace(MultiFrameSpace)
PDF space implementation for page-based annotations. This class provides a page-centric API for PDF annotations, using ā€˜pages’ terminology instead of ā€˜frames’ for all public methods.

put_object_instance

def put_object_instance(object_instance: ObjectInstance,
                        pages: Frames,
                        coordinates: GeometricCoordinates,
                        *,
                        on_overlap: FrameOverlapStrategy = "error",
                        created_at: Optional[datetime] = None,
                        created_by: Optional[str] = None,
                        last_edited_at: Optional[datetime] = None,
                        last_edited_by: Optional[str] = None,
                        confidence: Optional[float] = None,
                        manual_annotation: Optional[bool] = None) -> None
Add an object instance to specific pages in the PDF. Arguments:
  • object_instance - The object instance to add to the PDF.
  • pages - Page numbers or ranges where the object should appear. Can be:
    • A single page number (int)
    • A list of page numbers (List[int])
    • A Range object, specifying the start and end of the range (Range)
    • A list of Range objects for multiple ranges (List[Range])
  • coordinates - Geometric coordinates for the object (e.g., bounding box, polygon, polyline).
  • on_overlap - Strategy for handling existing annotations on the same pages.
    • ā€œerrorā€ (default): Raises an error if annotation already exists.
    • ā€œreplaceā€: Overwrites existing annotations on overlapping pages.
  • created_at - Optional timestamp when the annotation was created.
  • created_by - Optional identifier of who created the annotation.
  • last_edited_at - Optional timestamp when the annotation was last edited.
  • last_edited_by - Optional identifier of who last edited the annotation.
  • confidence - Optional confidence score for the annotation (0.0 to 1.0).
  • manual_annotation - Optional flag indicating if this was manually annotated.
Raises:
  • LabelRowError - If pages are invalid or if annotation already exists when on_overlap=ā€œerrorā€.

put_classification_instance

def put_classification_instance(
        classification_instance: ClassificationInstance,
        pages: Optional[Frames] = None,
        *,
        on_overlap: Optional[FrameOverlapStrategy] = "error",
        created_at: Optional[datetime] = None,
        created_by: Optional[str] = None,
        last_edited_at: Optional[datetime] = None,
        last_edited_by: Optional[str] = None,
        confidence: Optional[float] = None,
        manual_annotation: Optional[bool] = None) -> None
Add a classification instance to specific pages in the PDF. Arguments:
  • classification_instance - The classification instance to add to the PDF.
  • pages - Page numbers or ranges where the classification should appear. Can be:
    • A single page number (int)
    • A list of page numbers (List[int])
    • A Range object, specifying the start and end of the range (Range)
    • A list of Range objects for multiple ranges (List[Range]) For global classifications, set this to None.
  • on_overlap - Strategy for handling existing classifications on the same pages.
    • ā€œerrorā€ (default): Raises an error if classification already exists.
    • ā€œreplaceā€: Overwrites existing classifications on overlapping pages.
  • created_at - Optional timestamp when the annotation was created.
  • created_by - Optional identifier of who created the annotation.
  • last_edited_at - Optional timestamp when the annotation was last edited.
  • last_edited_by - Optional identifier of who last edited the annotation.
  • confidence - Optional confidence score for the annotation (0.0 to 1.0).
  • manual_annotation - Optional flag indicating if this was manually annotated.
Raises:
  • LabelRowError - If pages are invalid or if classification already exists when on_overlap=ā€œerrorā€.

remove_object_instance

def remove_object_instance(
        object_hash: str,
        pages: Optional[Frames] = None) -> Optional[ObjectInstance]
Remove an object instance from pages on the pdf space. If no pages are provided, the object instance is removed from ALL pages in the pdf. Arguments:
  • object_hash - The hash identifier of the object instance to remove.
  • pages - The pages the object instance is to be removed from.
Returns:
  • Optional[ObjectInstance] - The removed object instance, or None if the object wasn’t found.