What comes back from convert
Lesson 2 reached straight through .document and threw the rest away. The rest is how you find out whether the conversion went well.
convert returns a ConversionResult. The document is one field on it. The others say what was read, how it went, and what went wrong.
from docling.document_converter import DocumentConverter
result = DocumentConverter().convert("refunds.html")
print(result.status)
print(result.errors)status is one of four values: success, partial success, skipped, failure. errors is a list, empty here, that fills with one entry per thing that went wrong. Lesson 18 converts a folder and reads both of these for every file in it.
What was read
print(result.input.file.name)
print(result.input.format)
print(result.input.page_count)result.input describes the file that went in, including the format Docling decided it was. The page count is zero because HTML has no pages; only the formats that are laid out on paper fill it in, and lesson 14 reads it for the PDF.
The document knows where it came from
document = result.document
print(document.name)
print(document.origin.filename, "|", document.origin.mimetype)The origin travels with the document, which matters more than it looks. In lesson 29 a chunk of text taken from this document still knows it came from refunds.html, and that is what makes a citation possible.
- Print
result.input.format.valuefor all three text files. - Convert
shipping.mdand comparedocument.origin.mimetypewith the HTML one. - Print
result.status.nameand note it is a plain string you can put in a report.
Slow is fine. Stopping is the only problem.