Skip to content

Commit c31b107

Browse files
fix: prevent crash from invalid bbox coordinates in HTML export (#142)
Co-authored-by: samiullahchattha <[email protected]>
1 parent 8431395 commit c31b107

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

docling_eval/visualisation/visualisations.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,14 @@ def _get_document_visualization_data(
146146
logging.error(f"{page_no} not in page_imgs, get default image.")
147147
doc_img_b64 = from_pil_to_base64(get_missing_pageimg())
148148

149-
doc_page = doc.export_to_html(image_mode=ImageRefMode.EMBEDDED, page_no=page_no)
149+
try:
150+
doc_page = doc.export_to_html(image_mode=ImageRefMode.EMBEDDED, page_no=page_no)
151+
except ValueError as e:
152+
logging.error(
153+
f"Could not export page {page_no} to HTML due to a ValueError: {e}"
154+
)
155+
doc_page_body = f"<p>ERROR: Could not render page HTML due to invalid coordinates. Details: {e}</p>"
156+
return doc_img_b64, doc_page_body
150157

151158
# Search for the pattern in the HTML string
152159
mtch = pattern.search(doc_page)

0 commit comments

Comments
 (0)