Skip to content

Docling Document

This is an automatic generated API reference of the DoclingDocument type.

doc

Package for models defined by the Document type.

Classes:

DoclingDocument

Bases: BaseModel

DoclingDocument.

Methods:

Attributes:

body

body: GroupItem = GroupItem(
    name="_root_", self_ref="#/body"
)

furniture

furniture: GroupItem = GroupItem(
    name="_root_", self_ref="#/furniture"
)

groups

groups: List[GroupItem] = []

key_value_items

key_value_items: List[KeyValueItem] = []

name

name: str

origin

origin: Optional[DocumentOrigin] = None

pages

pages: Dict[int, PageItem] = {}

pictures

pictures: List[PictureItem] = []

schema_name

schema_name: Literal['DoclingDocument'] = 'DoclingDocument'

tables

tables: List[TableItem] = []

texts

texts: List[
    Union[SectionHeaderItem, ListItem, TextItem]
] = []

version

version: Annotated[
    str,
    StringConstraints(pattern=VERSION_PATTERN, strict=True),
] = CURRENT_VERSION

add_group

add_group(
    label: Optional[GroupLabel] = None,
    name: Optional[str] = None,
    parent: Optional[NodeItem] = None,
) -> GroupItem

add_group.

Parameters:

  • label (Optional[GroupLabel], default: None ) –

    Optional[GroupLabel]: (Default value = None)

  • name (Optional[str], default: None ) –

    Optional[str]: (Default value = None)

  • parent (Optional[NodeItem], default: None ) –

    Optional[NodeItem]: (Default value = None)

add_heading

add_heading(
    text: str,
    orig: Optional[str] = None,
    level: LevelNumber = 1,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
)

add_heading.

Parameters:

  • label

    DocItemLabel:

  • text (str) –

    str:

  • orig (Optional[str], default: None ) –

    Optional[str]: (Default value = None)

  • level (LevelNumber, default: 1 ) –

    LevelNumber: (Default value = 1)

  • prov (Optional[ProvenanceItem], default: None ) –

    Optional[ProvenanceItem]: (Default value = None)

  • parent (Optional[NodeItem], default: None ) –

    Optional[NodeItem]: (Default value = None)

add_list_item

add_list_item(
    text: str,
    enumerated: bool = False,
    marker: Optional[str] = None,
    orig: Optional[str] = None,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
)

add_list_item.

Parameters:

  • label

    str:

  • text (str) –

    str:

  • orig (Optional[str], default: None ) –

    Optional[str]: (Default value = None)

  • prov (Optional[ProvenanceItem], default: None ) –

    Optional[ProvenanceItem]: (Default value = None)

  • parent (Optional[NodeItem], default: None ) –

    Optional[NodeItem]: (Default value = None)

add_page

add_page(
    page_no: int,
    size: Size,
    image: Optional[ImageRef] = None,
) -> PageItem

add_page.

Parameters:

  • page_no (int) –

    int:

  • size (Size) –

    Size:

add_picture

add_picture(
    annotations: List[PictureDataType] = [],
    image: Optional[ImageRef] = None,
    caption: Optional[Union[TextItem, RefItem]] = None,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
)

add_picture.

Parameters:

  • data

    List[PictureData]: (Default value = [])

  • caption (Optional[Union[TextItem, RefItem]], default: None ) –

    Optional[Union[TextItem:

  • RefItem]]

    (Default value = None)

  • prov (Optional[ProvenanceItem], default: None ) –

    Optional[ProvenanceItem]: (Default value = None)

  • parent (Optional[NodeItem], default: None ) –

    Optional[NodeItem]: (Default value = None)

add_table

add_table(
    data: TableData,
    caption: Optional[Union[TextItem, RefItem]] = None,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
    label: DocItemLabel = TABLE,
)

add_table.

Parameters:

  • data (TableData) –

    TableData:

  • caption (Optional[Union[TextItem, RefItem]], default: None ) –

    Optional[Union[TextItem, RefItem]]: (Default value = None)

  • prov (Optional[ProvenanceItem], default: None ) –

    Optional[ProvenanceItem]: (Default value = None)

  • parent (Optional[NodeItem], default: None ) –

    Optional[NodeItem]: (Default value = None)

  • label (DocItemLabel, default: TABLE ) –

    DocItemLabel: (Default value = DocItemLabel.TABLE)

add_text

add_text(
    label: DocItemLabel,
    text: str,
    orig: Optional[str] = None,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
)

add_text.

Parameters:

  • label (DocItemLabel) –

    str:

  • text (str) –

    str:

  • orig (Optional[str], default: None ) –

    Optional[str]: (Default value = None)

  • prov (Optional[ProvenanceItem], default: None ) –

    Optional[ProvenanceItem]: (Default value = None)

  • parent (Optional[NodeItem], default: None ) –

    Optional[NodeItem]: (Default value = None)

add_title

add_title(
    text: str,
    orig: Optional[str] = None,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
)

add_title.

Parameters:

  • text (str) –

    str:

  • orig (Optional[str], default: None ) –

    Optional[str]: (Default value = None)

  • prov (Optional[ProvenanceItem], default: None ) –

    Optional[ProvenanceItem]: (Default value = None)

  • parent (Optional[NodeItem], default: None ) –

    Optional[NodeItem]: (Default value = None)

check_version_is_compatible

check_version_is_compatible(v: str) -> str

Check if this document version is compatible with current version.

export_to_dict

export_to_dict(
    mode: str = "json",
    by_alias: bool = True,
    exclude_none: bool = True,
) -> Dict

Export to dict.

export_to_document_tokens

export_to_document_tokens(
    delim: str = "\n",
    from_element: int = 0,
    to_element: int = maxsize,
    labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
    xsize: int = 100,
    ysize: int = 100,
    add_location: bool = True,
    add_content: bool = True,
    add_page_index: bool = True,
    add_table_cell_location: bool = False,
    add_table_cell_label: bool = True,
    add_table_cell_text: bool = True,
    page_no: Optional[int] = None,
    with_groups: bool = True,
    newline: bool = True,
) -> str

Exports the document content to a DocumentToken format.

Operates on a slice of the document's body as defined through arguments from_element and to_element; defaulting to the whole main_text.

Parameters:

  • delim (str, default: '\n' ) –

    str: (Default value = "\n\n")

  • from_element (int, default: 0 ) –

    int: (Default value = 0)

  • to_element (int, default: maxsize ) –

    Optional[int]: (Default value = None)

  • labels (set[DocItemLabel], default: DEFAULT_EXPORT_LABELS ) –

    set[DocItemLabel]

  • xsize (int, default: 100 ) –

    int: (Default value = 100)

  • ysize (int, default: 100 ) –

    int: (Default value = 100)

  • add_location (bool, default: True ) –

    bool: (Default value = True)

  • add_content (bool, default: True ) –

    bool: (Default value = True)

  • add_page_index (bool, default: True ) –

    bool: (Default value = True)

  • add_table_cell_label (bool, default: True ) –

    bool: (Default value = True)

  • add_table_cell_text (bool, default: True ) –

    bool: (Default value = True)

Returns:

  • str

    The content of the document formatted as a DocTags string.

export_to_element_tree

export_to_element_tree() -> str

Export_to_element_tree.

export_to_html

export_to_html(
    from_element: int = 0,
    to_element: int = maxsize,
    labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
    image_mode: ImageRefMode = PLACEHOLDER,
    page_no: Optional[int] = None,
    html_lang: str = "en",
    html_head: str = _HTML_DEFAULT_HEAD,
) -> str

Serialize to HTML.

export_to_markdown

export_to_markdown(
    delim: str = "\n",
    from_element: int = 0,
    to_element: int = maxsize,
    labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
    strict_text: bool = False,
    image_placeholder: str = "<!-- image -->",
    image_mode: ImageRefMode = PLACEHOLDER,
    indent: int = 4,
    text_width: int = -1,
    page_no: Optional[int] = None,
) -> str

Serialize to Markdown.

Operates on a slice of the document's body as defined through arguments from_element and to_element; defaulting to the whole document.

Parameters:

  • delim (str, default: '\n' ) –

    Delimiter to use when concatenating the various Markdown parts. (Default value = "\n").

  • from_element (int, default: 0 ) –

    Body slicing start index (inclusive). (Default value = 0).

  • to_element (int, default: maxsize ) –

    Body slicing stop index (exclusive). (Default value = maxint).

  • labels (set[DocItemLabel], default: DEFAULT_EXPORT_LABELS ) –

    The set of document labels to include in the export.

  • strict_text (bool, default: False ) –

    bool: Whether to only include the text content of the document. (Default value = False).

  • image_placeholder (str, default: '<!-- image -->' ) –

    The placeholder to include to position images in the markdown. (Default value = "\<!-- image -->").

  • image_mode (ImageRefMode, default: PLACEHOLDER ) –

    The mode to use for including images in the markdown. (Default value = ImageRefMode.PLACEHOLDER).

  • indent (int, default: 4 ) –

    The indent in spaces of the nested lists. (Default value = 4).

Returns:

  • str

    The exported Markdown representation.

export_to_text

export_to_text(
    delim: str = "\n\n",
    from_element: int = 0,
    to_element: int = 1000000,
    labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
) -> str

export_to_text.

iterate_items

iterate_items(
    root: Optional[NodeItem] = None,
    with_groups: bool = False,
    traverse_pictures: bool = False,
    page_no: Optional[int] = None,
    _level: int = 0,
) -> Iterable[Tuple[NodeItem, int]]

iterate_elements.

Parameters:

  • root (Optional[NodeItem], default: None ) –

    Optional[NodeItem]: (Default value = None)

  • with_groups (bool, default: False ) –

    bool: (Default value = False)

  • traverse_pictures (bool, default: False ) –

    bool: (Default value = True)

  • page_no (Optional[int], default: None ) –

    Optional[int]: (Default value = None)

  • _level (int, default: 0 ) –

    (Default value = 0)

load_from_json

load_from_json(filename: Path) -> DoclingDocument

load_from_json.

Parameters:

  • filename (Path) –

    The filename to load a saved DoclingDocument from a .json.

Returns:

  • DoclingDocument

    The loaded DoclingDocument.

num_pages

num_pages()

num_pages.

print_element_tree

print_element_tree()

Print_element_tree.

save_as_document_tokens

save_as_document_tokens(
    filename: Path,
    delim: str = "\n\n",
    from_element: int = 0,
    to_element: int = maxsize,
    labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
    xsize: int = 100,
    ysize: int = 100,
    add_location: bool = True,
    add_content: bool = True,
    add_page_index: bool = True,
    add_table_cell_location: bool = False,
    add_table_cell_label: bool = True,
    add_table_cell_text: bool = True,
    page_no: Optional[int] = None,
    with_groups: bool = True,
)

Save the document content to a DocumentToken format.

save_as_html

save_as_html(
    filename: Path,
    artifacts_dir: Optional[Path] = None,
    from_element: int = 0,
    to_element: int = maxsize,
    labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
    image_mode: ImageRefMode = PLACEHOLDER,
    page_no: Optional[int] = None,
    html_lang: str = "en",
    html_head: str = _HTML_DEFAULT_HEAD,
)

Save to HTML.

save_as_json

save_as_json(
    filename: Path,
    artifacts_dir: Optional[Path] = None,
    image_mode: ImageRefMode = EMBEDDED,
    indent: int = 2,
)

Save as json.

save_as_markdown

save_as_markdown(
    filename: Path,
    artifacts_dir: Optional[Path] = None,
    delim: str = "\n",
    from_element: int = 0,
    to_element: int = maxsize,
    labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
    strict_text: bool = False,
    image_placeholder: str = "<!-- image -->",
    image_mode: ImageRefMode = PLACEHOLDER,
    indent: int = 4,
    text_width: int = -1,
    page_no: Optional[int] = None,
)

Save to markdown.

save_as_yaml

save_as_yaml(
    filename: Path,
    artifacts_dir: Optional[Path] = None,
    image_mode: ImageRefMode = EMBEDDED,
    default_flow_style: bool = False,
)

Save as yaml.

validate_document

validate_document(d: DoclingDocument)

validate_document.

validate_tree

validate_tree(root) -> bool

validate_tree.

DocumentOrigin

Bases: BaseModel

FileSource.

Methods:

Attributes:

binary_hash

binary_hash: Uint64

filename

filename: str

mimetype

mimetype: str

uri

uri: Optional[AnyUrl] = None

parse_hex_string

parse_hex_string(value)

parse_hex_string.

validate_mimetype

validate_mimetype(v)

validate_mimetype.

DocItem

Bases: NodeItem

DocItem.

Methods:

Attributes:

children

children: List[RefItem] = []

label

label: DocItemLabel

model_config

model_config = ConfigDict(extra='forbid')

parent

parent: Optional[RefItem] = None

prov

prov: List[ProvenanceItem] = []

self_ref

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

get_image

get_image(doc: DoclingDocument) -> Optional[Image]

Returns the image of this DocItem.

The function returns None if this DocItem has no valid provenance or if a valid image of the page containing this DocItem is not available in doc.

get_location_tokens

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 100,
    ysize: int = 100,
    add_page_index: bool = True,
) -> str

Get the location string for the BaseCell.

get_ref

get_ref()

get_ref.

DocItemLabel

Bases: str, Enum

DocItemLabel.

Methods:

  • get_color

    Return the RGB color associated with a given label.

Attributes:

CAPTION

CAPTION = 'caption'

CHECKBOX_SELECTED

CHECKBOX_SELECTED = 'checkbox_selected'

CHECKBOX_UNSELECTED

CHECKBOX_UNSELECTED = 'checkbox_unselected'

CODE

CODE = 'code'

DOCUMENT_INDEX

DOCUMENT_INDEX = 'document_index'

FOOTNOTE

FOOTNOTE = 'footnote'

FORM

FORM = 'form'

FORMULA

FORMULA = 'formula'

KEY_VALUE_REGION

KEY_VALUE_REGION = 'key_value_region'

LIST_ITEM

LIST_ITEM = 'list_item'
PAGE_FOOTER = 'page_footer'

PAGE_HEADER

PAGE_HEADER = 'page_header'

PARAGRAPH

PARAGRAPH = 'paragraph'

PICTURE

PICTURE = 'picture'

REFERENCE

REFERENCE = 'reference'

SECTION_HEADER

SECTION_HEADER = 'section_header'

TABLE

TABLE = 'table'

TEXT

TEXT = 'text'

TITLE

TITLE = 'title'

get_color

get_color(label: DocItemLabel) -> Tuple[int, int, int]

Return the RGB color associated with a given label.

ProvenanceItem

Bases: BaseModel

ProvenanceItem.

Attributes:

bbox

charspan

charspan: Tuple[int, int]

page_no

page_no: int

GroupItem

Bases: NodeItem

GroupItem.

Methods:

Attributes:

children

children: List[RefItem] = []

label

model_config

model_config = ConfigDict(extra='forbid')

name

name: str = 'group'

parent

parent: Optional[RefItem] = None

self_ref

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

get_ref

get_ref()

get_ref.

GroupLabel

Bases: str, Enum

GroupLabel.

Attributes:

CHAPTER

CHAPTER = 'chapter'

COMMENT_SECTION

COMMENT_SECTION = 'comment_section'

FORM_AREA

FORM_AREA = 'form_area'

KEY_VALUE_AREA

KEY_VALUE_AREA = 'key_value_area'

LIST

LIST = 'list'

ORDERED_LIST

ORDERED_LIST = 'ordered_list'

SECTION

SECTION = 'section'

SHEET

SHEET = 'sheet'

SLIDE

SLIDE = 'slide'

UNSPECIFIED

UNSPECIFIED = 'unspecified'

NodeItem

Bases: BaseModel

NodeItem.

Methods:

Attributes:

children

children: List[RefItem] = []

model_config

model_config = ConfigDict(extra='forbid')

parent

parent: Optional[RefItem] = None

self_ref

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

get_ref

get_ref()

get_ref.

PageItem

Bases: BaseModel

PageItem.

Attributes:

image

image: Optional[ImageRef] = None

page_no

page_no: int

size

size: Size

FloatingItem

Bases: DocItem

FloatingItem.

Methods:

Attributes:

captions

captions: List[RefItem] = []

children

children: List[RefItem] = []

footnotes

footnotes: List[RefItem] = []

image

image: Optional[ImageRef] = None

label

label: DocItemLabel

model_config

model_config = ConfigDict(extra='forbid')

parent

parent: Optional[RefItem] = None

prov

prov: List[ProvenanceItem] = []

references

references: List[RefItem] = []

self_ref

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

caption_text

caption_text(doc: DoclingDocument) -> str

Computes the caption as a single text.

get_image

get_image(doc: DoclingDocument) -> Optional[Image]

Returns the image corresponding to this FloatingItem.

This function returns the PIL image from self.image if one is available. Otherwise, it uses DocItem.get_image to get an image of this FloatingItem.

In particular, when self.image is None, the function returns None if this FloatingItem has no valid provenance or the doc does not contain a valid image for the required page.

get_location_tokens

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 100,
    ysize: int = 100,
    add_page_index: bool = True,
) -> str

Get the location string for the BaseCell.

get_ref

get_ref()

get_ref.

TextItem

Bases: DocItem

TextItem.

Methods:

Attributes:

children

children: List[RefItem] = []

model_config

model_config = ConfigDict(extra='forbid')

orig

orig: str

parent

parent: Optional[RefItem] = None

prov

prov: List[ProvenanceItem] = []

self_ref

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

text

text: str

export_to_document_tokens

export_to_document_tokens(
    doc: DoclingDocument,
    new_line: str = "\n",
    xsize: int = 100,
    ysize: int = 100,
    add_location: bool = True,
    add_content: bool = True,
    add_page_index: bool = True,
)

Export text element to document tokens format.

Parameters:

  • doc (DoclingDocument) –

    "DoclingDocument":

  • new_line (str, default: '\n' ) –

    str: (Default value = "\n")

  • xsize (int, default: 100 ) –

    int: (Default value = 100)

  • ysize (int, default: 100 ) –

    int: (Default value = 100)

  • add_location (bool, default: True ) –

    bool: (Default value = True)

  • add_content (bool, default: True ) –

    bool: (Default value = True)

  • add_page_index (bool, default: True ) –

    bool: (Default value = True)

get_image

get_image(doc: DoclingDocument) -> Optional[Image]

Returns the image of this DocItem.

The function returns None if this DocItem has no valid provenance or if a valid image of the page containing this DocItem is not available in doc.

get_location_tokens

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 100,
    ysize: int = 100,
    add_page_index: bool = True,
) -> str

Get the location string for the BaseCell.

get_ref

get_ref()

get_ref.

TableItem

Bases: FloatingItem

TableItem.

Methods:

Attributes:

captions

captions: List[RefItem] = []

children

children: List[RefItem] = []

data

data: TableData

footnotes

footnotes: List[RefItem] = []

image

image: Optional[ImageRef] = None

label

label: Literal[DOCUMENT_INDEX, TABLE] = TABLE

model_config

model_config = ConfigDict(extra='forbid')

parent

parent: Optional[RefItem] = None

prov

prov: List[ProvenanceItem] = []

references

references: List[RefItem] = []

self_ref

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

caption_text

caption_text(doc: DoclingDocument) -> str

Computes the caption as a single text.

export_to_dataframe

export_to_dataframe() -> DataFrame

Export the table as a Pandas DataFrame.

export_to_document_tokens

export_to_document_tokens(
    doc: DoclingDocument,
    new_line: str = "\n",
    xsize: int = 100,
    ysize: int = 100,
    add_location: bool = True,
    add_caption: bool = True,
    add_content: bool = True,
    add_cell_location: bool = True,
    add_cell_label: bool = True,
    add_cell_text: bool = True,
    add_page_index: bool = True,
)

Export table to document tokens format.

Parameters:

  • doc (DoclingDocument) –

    "DoclingDocument":

  • new_line (str, default: '\n' ) –

    str: (Default value = "\n")

  • xsize (int, default: 100 ) –

    int: (Default value = 100)

  • ysize (int, default: 100 ) –

    int: (Default value = 100)

  • add_location (bool, default: True ) –

    bool: (Default value = True)

  • add_caption (bool, default: True ) –

    bool: (Default value = True)

  • add_content (bool, default: True ) –

    bool: (Default value = True)

  • add_cell_location (bool, default: True ) –

    bool: (Default value = True)

  • add_cell_label (bool, default: True ) –

    bool: (Default value = True)

  • add_cell_text (bool, default: True ) –

    bool: (Default value = True)

  • add_page_index (bool, default: True ) –

    bool: (Default value = True)

export_to_html

export_to_html(
    doc: Optional[DoclingDocument] = None,
    add_caption: bool = True,
) -> str

Export the table as html.

export_to_markdown

export_to_markdown() -> str

Export the table as markdown.

export_to_otsl

export_to_otsl(
    doc: DoclingDocument,
    add_cell_location: bool = True,
    add_cell_text: bool = True,
    xsize: int = 100,
    ysize: int = 100,
) -> str

Export the table as OTSL.

get_image

get_image(doc: DoclingDocument) -> Optional[Image]

Returns the image corresponding to this FloatingItem.

This function returns the PIL image from self.image if one is available. Otherwise, it uses DocItem.get_image to get an image of this FloatingItem.

In particular, when self.image is None, the function returns None if this FloatingItem has no valid provenance or the doc does not contain a valid image for the required page.

get_location_tokens

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 100,
    ysize: int = 100,
    add_page_index: bool = True,
) -> str

Get the location string for the BaseCell.

get_ref

get_ref()

get_ref.

TableCell

Bases: BaseModel

TableCell.

Methods:

Attributes:

bbox

bbox: Optional[BoundingBox] = None

col_span

col_span: int = 1

column_header

column_header: bool = False

end_col_offset_idx

end_col_offset_idx: int

end_row_offset_idx

end_row_offset_idx: int

row_header

row_header: bool = False

row_section

row_section: bool = False

row_span

row_span: int = 1

start_col_offset_idx

start_col_offset_idx: int

start_row_offset_idx

start_row_offset_idx: int

text

text: str

from_dict_format

from_dict_format(data: Any) -> Any

from_dict_format.

TableData

Bases: BaseModel

BaseTableData.

Attributes:

grid

grid: List[List[TableCell]]

grid.

num_cols

num_cols: int = 0

num_rows

num_rows: int = 0

table_cells

table_cells: List[TableCell] = []

TableCellLabel

Bases: str, Enum

TableCellLabel.

Attributes:

BODY

BODY = 'body'

COLUMN_HEADER

COLUMN_HEADER = 'col_header'

ROW_HEADER

ROW_HEADER = 'row_header'

ROW_SECTION

ROW_SECTION = 'row_section'

KeyValueItem

Bases: DocItem

KeyValueItem.

Methods:

Attributes:

children

children: List[RefItem] = []

label

model_config

model_config = ConfigDict(extra='forbid')

parent

parent: Optional[RefItem] = None

prov

prov: List[ProvenanceItem] = []

self_ref

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

get_image

get_image(doc: DoclingDocument) -> Optional[Image]

Returns the image of this DocItem.

The function returns None if this DocItem has no valid provenance or if a valid image of the page containing this DocItem is not available in doc.

get_location_tokens

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 100,
    ysize: int = 100,
    add_page_index: bool = True,
) -> str

Get the location string for the BaseCell.

get_ref

get_ref()

get_ref.

SectionHeaderItem

Bases: TextItem

SectionItem.

Methods:

Attributes:

children

children: List[RefItem] = []

label

label: Literal[SECTION_HEADER] = SECTION_HEADER

level

level: LevelNumber = 1

model_config

model_config = ConfigDict(extra='forbid')

orig

orig: str

parent

parent: Optional[RefItem] = None

prov

prov: List[ProvenanceItem] = []

self_ref

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

text

text: str

export_to_document_tokens

export_to_document_tokens(
    doc: DoclingDocument,
    new_line: str = "\n",
    xsize: int = 100,
    ysize: int = 100,
    add_location: bool = True,
    add_content: bool = True,
    add_page_index: bool = True,
)

Export text element to document tokens format.

Parameters:

  • doc (DoclingDocument) –

    "DoclingDocument":

  • new_line (str, default: '\n' ) –

    str: (Default value = "\n")

  • xsize (int, default: 100 ) –

    int: (Default value = 100)

  • ysize (int, default: 100 ) –

    int: (Default value = 100)

  • add_location (bool, default: True ) –

    bool: (Default value = True)

  • add_content (bool, default: True ) –

    bool: (Default value = True)

  • add_page_index (bool, default: True ) –

    bool: (Default value = True)

get_image

get_image(doc: DoclingDocument) -> Optional[Image]

Returns the image of this DocItem.

The function returns None if this DocItem has no valid provenance or if a valid image of the page containing this DocItem is not available in doc.

get_location_tokens

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 100,
    ysize: int = 100,
    add_page_index: bool = True,
) -> str

Get the location string for the BaseCell.

get_ref

get_ref()

get_ref.

PictureItem

Bases: FloatingItem

PictureItem.

Methods:

Attributes:

annotations

annotations: List[PictureDataType] = []

captions

captions: List[RefItem] = []

children

children: List[RefItem] = []

footnotes

footnotes: List[RefItem] = []

image

image: Optional[ImageRef] = None

label

label: Literal[PICTURE] = PICTURE

model_config

model_config = ConfigDict(extra='forbid')

parent

parent: Optional[RefItem] = None

prov

prov: List[ProvenanceItem] = []

references

references: List[RefItem] = []

self_ref

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

caption_text

caption_text(doc: DoclingDocument) -> str

Computes the caption as a single text.

export_to_document_tokens

export_to_document_tokens(
    doc: DoclingDocument,
    new_line: str = "\n",
    xsize: int = 100,
    ysize: int = 100,
    add_location: bool = True,
    add_caption: bool = True,
    add_content: bool = True,
    add_page_index: bool = True,
)

Export picture to document tokens format.

Parameters:

  • doc (DoclingDocument) –

    "DoclingDocument":

  • new_line (str, default: '\n' ) –

    str: (Default value = "\n")

  • xsize (int, default: 100 ) –

    int: (Default value = 100)

  • ysize (int, default: 100 ) –

    int: (Default value = 100)

  • add_location (bool, default: True ) –

    bool: (Default value = True)

  • add_caption (bool, default: True ) –

    bool: (Default value = True)

  • add_content (bool, default: True ) –

    bool: (Default value = True)

export_to_html

export_to_html(
    doc: DoclingDocument,
    add_caption: bool = True,
    image_mode: ImageRefMode = PLACEHOLDER,
) -> str

Export picture to HTML format.

export_to_markdown

export_to_markdown(
    doc: DoclingDocument,
    add_caption: bool = True,
    image_mode: ImageRefMode = EMBEDDED,
    image_placeholder: str = "<!-- image -->",
) -> str

Export picture to Markdown format.

get_image

get_image(doc: DoclingDocument) -> Optional[Image]

Returns the image corresponding to this FloatingItem.

This function returns the PIL image from self.image if one is available. Otherwise, it uses DocItem.get_image to get an image of this FloatingItem.

In particular, when self.image is None, the function returns None if this FloatingItem has no valid provenance or the doc does not contain a valid image for the required page.

get_location_tokens

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 100,
    ysize: int = 100,
    add_page_index: bool = True,
) -> str

Get the location string for the BaseCell.

get_ref

get_ref()

get_ref.

ImageRef

Bases: BaseModel

ImageRef.

Methods:

Attributes:

dpi

dpi: int

mimetype

mimetype: str

pil_image

pil_image: Optional[Image]

Return the PIL Image.

size

size: Size

uri

uri: Union[AnyUrl, Path] = Field(union_mode="left_to_right")

from_pil

from_pil(image: Image, dpi: int) -> Self

Construct ImageRef from a PIL Image.

validate_mimetype

validate_mimetype(v)

validate_mimetype.

PictureClassificationClass

Bases: BaseModel

PictureClassificationData.

Attributes:

class_name

class_name: str

confidence

confidence: float

PictureClassificationData

Bases: BasePictureData

PictureClassificationData.

Attributes:

kind

kind: Literal['classification'] = 'classification'

predicted_classes

predicted_classes: List[PictureClassificationClass]

provenance

provenance: str

RefItem

Bases: BaseModel

RefItem.

Methods:

Attributes:

cref

cref: str = Field(alias="$ref", pattern=_JSON_POINTER_REGEX)

model_config

model_config = ConfigDict(populate_by_name=True)

get_ref

get_ref()

get_ref.

resolve

resolve(doc: DoclingDocument)

resolve.

BoundingBox

Bases: BaseModel

BoundingBox.

Methods:

Attributes:

b

b: float

coord_origin

coord_origin: CoordOrigin = TOPLEFT

height

height

height.

l

l: float

r

r: float

t

t: float

width

width

width.

area

area() -> float

area.

as_tuple

as_tuple()

as_tuple.

from_tuple

from_tuple(coord: Tuple[float, ...], origin: CoordOrigin)

from_tuple.

Parameters:

  • coord (Tuple[float, ...]) –

    Tuple[float:

  • ...]
  • origin (CoordOrigin) –

    CoordOrigin:

intersection_area_with

intersection_area_with(other: BoundingBox) -> float

intersection_area_with.

Parameters:

normalized

normalized(page_size: Size) -> BoundingBox

normalized.

Parameters:

  • page_size (Size) –

    Size:

scaled

scaled(scale: float) -> BoundingBox

scaled.

Parameters:

  • scale (float) –

    float:

to_bottom_left_origin

to_bottom_left_origin(page_height) -> BoundingBox

to_bottom_left_origin.

Parameters:

  • page_height

to_top_left_origin

to_top_left_origin(page_height)

to_top_left_origin.

Parameters:

  • page_height

CoordOrigin

Bases: str, Enum

CoordOrigin.

Attributes:

BOTTOMLEFT

BOTTOMLEFT = 'BOTTOMLEFT'

TOPLEFT

TOPLEFT = 'TOPLEFT'

ImageRefMode

Bases: str, Enum

ImageRefMode.

Attributes:

EMBEDDED

EMBEDDED = 'embedded'

PLACEHOLDER

PLACEHOLDER = 'placeholder'

REFERENCED

REFERENCED = 'referenced'

Size

Bases: BaseModel

Size.

Methods:

Attributes:

height

height: float = 0.0

width

width: float = 0.0

as_tuple

as_tuple()

as_tuple.