Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
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.pptxindex a18f3ffe..d515e5f4 100644Binary files a/demo/office_docs/pptx_01.pptx and b/demo/office_docs/pptx_01.pptx differdiff --git a/mineru/backend/utils/office_chart.py b/mineru/backend/utils/office_chart.pynew file mode 100644index 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.pyindex 921965f7..4fce717c 100644--- a/mineru/model/docx/docx_converter.py+++ b/mineru/model/docx/docx_converter.py@@ -5,7 +5,6 @@ from io import BytesIOfrom pathlib import Pathfrom typing import BinaryIO, Optional, Union, Any, Final, Iterator-import pandas as pdfrom PIL import Imagefrom loguru import loggerfrom 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_bytesfrom mineru.utils.pdf_reader import image_to_b64strclass 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-@staticmethoddef _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.pyindex 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_bytesfrom mineru.model.pptx.xycut_pp_sorter import sort_entriesfrom 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: