Parsed Page Access and Segmentation#
Page.parsed_page is the central entry point for backend-produced text cells and their geometry. After a backend parses a page, it stores a SegmentedPdfPage (or the base SegmentedPage) in Page.parsed_page . The pipeline then accesses the cells via the page.cells property, which is a thin alias for parsed_page.textline_cells .
Data Model#
All types are defined in docling_core/types/doc/page.py.
TextCell and PdfTextCell#
TextCell is the base unit. Key fields:
| Field | Description |
|---|---|
rect: BoundingRectangle | Oriented 4-corner bounding rectangle |
text | Normalized text string |
orig | Raw, pre-normalization text from the backend |
text_direction | LEFT_TO_RIGHT, RIGHT_TO_LEFT, or UNSPECIFIED |
confidence | 1.0 for digital text; OCR score for OCR-produced cells |
from_ocr | True if produced by OCR |
PdfTextCell extends TextCell with rendering_mode (PDF32000 text rendering mode), widget, font_key, and font_name.
BoundingRectangle#
BoundingRectangle stores four explicit corner points (r_x0/r_y0 … r_x3/r_y3) rather than a simple LTRB box, enabling representation of rotated text. The default coord_origin is BOTTOMLEFT (matching PDF native coordinates). Use to_top_left_origin(page_height) / to_bottom_left_origin(page_height) to convert. to_bounding_box() returns an axis-aligned BoundingBox for overlap arithmetic.
SegmentedPage / SegmentedPdfPage#
SegmentedPage holds three granularity levels:
| Field | Granularity | Populated when |
|---|---|---|
char_cells | Character | has_chars = True |
word_cells | Word | has_words = True |
textline_cells | Line | has_lines = True |
The has_chars / has_words / has_lines boolean flags distinguish "not computed" from "computed but empty" . Additional fields: bitmap_resources, widgets, hyperlinks, and an optional rendered image.
SegmentedPdfPage narrows dimension to PdfPageGeometry (exposes all five PDF boundary boxes: art, bleed, crop, media, trim) and refines the cell lists to list[Union[PdfTextCell, TextCell]]. It also holds shapes (vector graphics as PdfShape instances).
TextCellUnit is the enum (CHAR, WORD, LINE) used by iterators and query methods.
Coordinate System#
docling-parse emits coordinates in bottom-left origin (native PDF). Immediately after get_page() returns, _ensure_parsed() flips every cell list to top-left origin so the rest of the pipeline operates in a single consistent frame . All downstream code—layout models, table assembly—therefore receives top-left coordinates.
BoundingBox in docling_core/types/doc/base.py stores CoordOrigin alongside every box and enforces origin consistency in overlap/IoU calculations.
How Backends Populate parsed_page#
docling-parse (default PDF backend)#
DoclingParsePageBackend._ensure_parsed() is lazily called before any cell access . It creates a ContentConfig via _make_docling_parse_page_content_config() which controls what is materialized:
textline_cells— always materialized (the pipeline's primary input)word_cells— materialized whencreate_words=Truechar_cells— computed but not materialized unlesskeep_chars=True; char-level data drives word grouping but is discarded by defaultbitmap_resources— rectangle only (bitmap bytes never loaded)
get_text_cells() returns textline_cells for the layout pipeline . get_text_in_rect() filters textline cells by ≥50% intersection-over-self with a query bbox—used by table-cell text matching .
Other backends#
| Backend | File | Notes |
|---|---|---|
pypdfium2_backend | pypdfium2_backend.py | get_segmented_page() builds SegmentedPdfPage from pypdfium2 text extraction |
mets_gbs_backend | mets_gbs_backend.py | Parses hOCR XML; fills textline_cells and word_cells with OCR confidence scores |
image_backend | image_backend.py | Returns empty SegmentedPdfPage; all cell lists are empty |
All backends expose the same PdfPageBackend interface (get_text_cells(), get_text_in_rect(), get_segmented_page()), making cell access polymorphic regardless of backend.
Key Query Methods on SegmentedPdfPage#
All defined in docling_core/types/doc/page.py:
iterate_cells(unit_type)— yields cells for a givenTextCellUnitget_cells_in_bbox(cell_unit, bbox, ios=0.8)— returns cells with intersection-over-self > threshold; handles cross-origin comparisons automaticallycrop_text(cell_unit, bbox)— extracts concatenated text from cells fully contained in a bboxexport_to_textlines(cell_unit, ...)— debug-friendly text export with location, font, and direction metadatarender_as_image(cell_unit, ...)— PIL image rendering with overlaid cell rectangles, shapes, bitmaps, and hyperlinks
Primary Source Files#
| File | Purpose |
|---|---|
docling_core/types/doc/page.py | All segmented-page types: SegmentedPage, SegmentedPdfPage, TextCell, BoundingRectangle, TextCellUnit |
docling_core/types/doc/base.py | BoundingBox, CoordOrigin |
docling/datamodel/base_models.py | Page.parsed_page field and Page.cells property |
docling/backend/docling_parse_backend.py | _make_docling_parse_page_content_config(), _ensure_parsed(), get_text_cells(), get_text_in_rect() |
docling/backend/mets_gbs_backend.py | OCR-sourced SegmentedPdfPage construction from hOCR |