Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

feat: improve gap tolerance selection by introducing preference margin

myhlolib62227433985
diff --git a/demo/office_docs/pptx_01.pptx b/demo/office_docs/pptx_01.pptx
index a18f3ffe..d515e5f4 100644
Binary files a/demo/office_docs/pptx_01.pptx and b/demo/office_docs/pptx_01.pptx differ
diff --git a/mineru/backend/utils/office_chart.py b/mineru/backend/utils/office_chart.py
new file mode 100644
index 00000000..bd535fcb
--- /dev/null
+++ b/mineru/backend/utils/office_chart.py
@@ -0,0 +1,30 @@
+import re
+from io import BytesIO
+
+import pandas as pd
+
+
+def minify_html(html: str) -> str:
+ """Strip formatting whitespace from HTML while preserving content."""
+ if not html:
+ return html
+
+ html = re.sub(r'>\s+<', '><', html)
+ html = re.sub(r'\n\s*', '', html)
+ return html
+
+
+def html_table_from_excel_bytes(excel_bytes: bytes) -> str:
+ """Convert the first non-empty worksheet in an embedded workbook to HTML."""
+ if not excel_bytes:
+ return ""
+
+ worksheets = pd.read_excel(BytesIO(excel_bytes), sheet_name=None)
+ for dataframe in worksheets.values():
+ if dataframe is None:
+ continue
+ if dataframe.empty and len(dataframe.columns) == 0:
+ continue
+ return minify_html(dataframe.to_html(index=False, header=True))
+
+ return ""
diff --git a/mineru/model/docx/docx_converter.py b/mineru/model/docx/docx_converter.py
index 921965f7..4fce717c 100644
--- a/mineru/model/docx/docx_converter.py
+++ b/mineru/model/docx/docx_converter.py
@@ -5,7 +5,6 @@ from io import BytesIO
from pathlib import Path
from typing import BinaryIO, Optional, Union, Any, Final, Iterator
-import pandas as pd
from PIL import Image
from loguru import logger
from docx import Document
@@ -27,6 +26,7 @@ from mineru.backend.utils.office_image import (
is_vector_image,
serialize_vector_image_with_placeholder,
)
+from mineru.backend.utils.office_chart import html_table_from_excel_bytes
from mineru.utils.pdf_reader import image_to_b64str
class DocxConverter:
@@ -120,25 +120,6 @@ class DocxConverter:
text = text.replace("[", "\\[").replace("]", "\\]")
return text
- @staticmethod
- def _minify_html(html: str) -> str:
- """
- 移除HTML中的格式化空白(换行、缩进等)。
-
- Args:
- html: 要处理的HTML字符串
-
- Returns:
- str: 去除格式化后的HTML
- """
- if not html:
- return html
- # 移除标签之间的换行符和制表符
- html = re.sub(r'>\s+<', '><', html)
- # 移除行首尾无关的空白
- html = re.sub(r'\n\s*', '', html)
- return html
-
@staticmethod
def _escape_hyperlink_url(url: str) -> str:
"""
@@ -2622,9 +2603,9 @@ class DocxConverter:
for path_name, chart_idx in idx_xlsx_map.items():
if name.endswith(path_name):
content = zf.read(name)
- excel_data = pd.read_excel(BytesIO(content))
- html = excel_data.to_html(index=False, header=True)
- self.chart_list[chart_idx - 1]["content"] = self._minify_html(html)
+ self.chart_list[chart_idx - 1]["content"] = (
+ html_table_from_excel_bytes(content)
+ )
def _handle_textbox_content(
self,
diff --git a/mineru/model/pptx/pptx_converter.py b/mineru/model/pptx/pptx_converter.py
index e65af9da..5365003d 100644
--- a/mineru/model/pptx/pptx_converter.py
+++ b/mineru/model/pptx/pptx_converter.py
@@ -17,6 +17,7 @@ from mineru.backend.utils.office_image import (
is_vector_image,
serialize_vector_image_with_placeholder,
)
+from mineru.backend.utils.office_chart import html_table_from_excel_bytes
from mineru.model.pptx.xycut_pp_sorter import sort_entries
from mineru.utils.pdf_reader import image_to_b64str
@@ -198,6 +199,9 @@ class PptxConverter:
if shape.has_table:
self._handle_tables(shape)
+ if getattr(shape, "has_chart", False):
+ self._handle_chart(shape)
+
if shape.shape_type == MSO_SHAPE_TYPE.PICTURE:
later_shapes = linear_shapes[shape_index + 1 :]
if not self._should_skip_picture(
@@ -575,6 +579,29 @@ class PptxConverter:
return None
+ def _handle_chart(self, shape) -> None:
+ try:
+ chart_workbook = shape.chart.part.chart_workbook
+ xlsx_part = chart_workbook.xlsx_part
+ if xlsx_part is None:
+ logger.warning("Warning: chart workbook part is missing")
+ return
+
+ chart_html = html_table_from_excel_bytes(xlsx_part.blob)
+ except Exception as e:
+ logger.warning(f"Warning: chart workbook cannot be loaded: {e}")
+ return
+
+ if not chart_html:
+ return
+
+ self.cur_page.append(
+ {
+ "type": BlockType.CHART,
+ "content": chart_html,
+ }
+ )
+
def _handle_pictures(self, shape):
image_data = self._get_shape_image_data(shape)
if image_data is None: