Repository navigation
Page numbers and bounding boxes for DOCX: filling prov in Docling's own output from a Word-compatible layout engine
#5066
Ryujiyasu
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Docling's DOCX backend leaves
provempty, for the reason given each time it comes up (#450, #833, #997, #1757, #2865): a .docx stores no layout, so there is no page to point at. The usual advice is to print to PDF first.I work on Oxi, an open-source (MPL-2.0) Rust/Wasm layout engine for .docx whose pagination is measured against Word's own render. I wrote a small tool that takes the DoclingDocument Docling already produces for a DOCX, plus the same file, and fills in
provandpagesfrom Oxi's layout. Docling's structure, labels and text are left exactly as they are; nothing in Docling needs to change for this to work.A section header from
tests/data/docx/sources/word_sample.docxafter annotation (points, top-left origin,charspanoverorig, one entry per page an item spans):{ "self_ref": "#/texts/4", "label": "section_header", "text": "Let’s swim!", "prov": [{"page_no": 1, "bbox": {"l": 66.95, "t": 380.98, "r": 167.86, "b": 405.13, "coord_origin": "TOPLEFT"}, "charspan": [0, 11]}] }Checked on this repository's
tests/data/docxwith its ground-truth JSON as input (36 files, 845 items):prov; table cells also getbbox;DoclingDocument_1_10.json, with refs, pages, boxes and charspans checked;prov,pagesand cellbbox.How close the pages are to Word: Oxi is scored on frozen blind sets of public documents against Word's own render (method and per-engine numbers in its README). Pagination is not perfect, and a document using a font the engine has no metrics for can paginate differently from Word. Placement rules are written down in the tool's README, including the two estimated cases (an empty paragraph the engine paints nothing for, and a comment, which takes the place of the text it annotates).
Try it:
One question for the maintainers: is DOCX
provfrom an external producer something you would want to point users to (docs, an example), or would you rather keep DOCX provenance out of the Docling ecosystem by design?Related: docling.rs drops
provandpageswhen it reads a DoclingDocument JSON (docling-project/docling.rs#899), so for now the annotated JSON should be consumed with Python docling-core.All reactions