Doclingdocling 2.127.0 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
26 small wins to finish your pathNext lesson

Plain text, and HTML that keeps the spans

Two more exports, and the choice between them is really a choice about what you are going to do with the result.

Plain text is less plain than it sounds

Example
print(document.export_to_text())

The heading markers are gone, which is what plain means. The table is not gone: it is still a Markdown table, pipes and all, because there is no way to write a grid in plain text and Docling does not invent one.

So export_to_text is the right export when you want the words without the markup getting counted as words, and the wrong one if you were expecting the table to disappear.

HTML keeps everything Markdown dropped

Example
from docling.document_converter import DocumentConverter

couriers = DocumentConverter().convert("couriers.html").document
print(couriers.tables[0].export_to_html(couriers))

There is the rowspan that lesson 10's Markdown had to flatten. HTML has the syntax for it, so the serializer uses it. When a merged header cell matters to whatever reads your output, this is the export to use.

A whole page, not a fragment

Example
page = document.export_to_html()
print(len(page.splitlines()), "lines")
print(page.splitlines()[0])

export_to_html on the document writes a complete page with a stylesheet in it, ready to open in a browser. export_to_html on a single table, as above, writes just that table. Two methods with the same name at two levels, and the difference catches people out.

Choosing

You want toUseBecause
Feed a modelexport_to_markdownCompact, and models read it well
Count or search wordsexport_to_textNo heading markers in the way
Keep merged cellsexport_to_htmlThe only text export with span syntax
Store and reloadsave_as_jsonThe only one that loses nothing
Every export takes the same filters. labels, from_element, to_element and page_no work on Markdown, text and HTML alike, so a rule you worked out on one applies to the others.
Try it yourself
  • Export refunds.html as text and count the pipe characters.
  • Open the exported HTML page in a browser.
  • Call export_to_html(page_no=2) on the PDF once you reach lesson 13.

Little by little, you're building something great.