Skip to content

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

feat: enhance image path handling for base64 images in page info processing

myhlolie0cffb90189a
diff --git a/mineru/backend/office/model_output_to_middle_json.py b/mineru/backend/office/model_output_to_middle_json.py
index a3c012b5..d5ce5097 100644
--- a/mineru/backend/office/model_output_to_middle_json.py
+++ b/mineru/backend/office/model_output_to_middle_json.py
@@ -6,6 +6,7 @@ from collections import defaultdict
from typing import Any
from ...types import Block, BlockType, PageInfo
+from ...utils.image_payload import image_path_from_data_uri
from .office_magic_model import MagicModel
@@ -44,9 +45,22 @@ def blocks_to_page_info(page_blocks: list[dict[str, Any]], image_writer: Any, pa
page_idx=page_index,
_backend="office",
)
+ _populate_image_paths_from_base64(page_info)
return page_info
+def _populate_image_paths_from_base64(page_info: PageInfo) -> None:
+ """为 Office 内联 base64 图片生成稳定 image_path,保留图片字节给后续统一写出。"""
+ for block_list in (page_info.para_blocks, page_info.discarded_blocks):
+ for block in block_list:
+ for span in block.all_spans():
+ if span.image_path or not span.image_base64:
+ continue
+ image_path = image_path_from_data_uri(span.image_base64)
+ if image_path is not None:
+ span.image_path = image_path
+
+
def _extract_section_parts_from_content(content: str, level: int) -> list[int] | None:
"""Try to extract a leading section number (e.g. '1.2.1') from title content.
diff --git a/mineru/backend/office/office_magic_model.py b/mineru/backend/office/office_magic_model.py
index 9b7bc98f..c2850586 100644
--- a/mineru/backend/office/office_magic_model.py
+++ b/mineru/backend/office/office_magic_model.py
@@ -664,9 +664,10 @@ def fix_two_layer_blocks(blocks: list[Block], fix_type: Literal["image", "table"
# 添加未处理的blocks
for block in blocks:
- block.type = ""
- if block.index not in processed_indices and block not in not_include_blocks:
- not_include_blocks.append(block)
+ if block.index not in processed_indices:
+ block.type = ""
+ if block not in not_include_blocks:
+ not_include_blocks.append(block)
return fixed_blocks, not_include_blocks