Skip to content

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

fix: remove unsupported span bbox visualization functionality

myhlolia2ad5e1594a6
diff --git a/README_en.md b/README_en.md
index b057f9c6..e45e5b0b 100644
--- a/README_en.md
+++ b/README_en.md
@@ -173,7 +173,7 @@ https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c
- Automatically detect scanned PDFs and garbled PDFs and enable OCR functionality.
- OCR supports detection and recognition of 109 languages.
- Supports multiple output formats, such as multimodal and NLP Markdown, JSON sorted by reading order, and rich intermediate formats.
-- Supports various visualization results, including layout visualization and span visualization, for efficient confirmation of output quality.
+- Supports layout visualization for efficient confirmation of output quality.
- Built-in CLI, FastAPI, Gradio WebUI, for local orchestration and multi-service deployment.
- Supports running in a pure CPU environment, and also supports GPU/MPS acceleration
- Compatible with Windows, Linux, and Mac platforms.
diff --git a/README_zh.md b/README_zh.md
index 9a87275d..6a674c3c 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -172,7 +172,7 @@ https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c
- 自动检测扫描版PDF和乱码PDF,并启用OCR功能
- OCR支持109种语言的检测与识别
- 支持多种输出格式,如多模态与NLP的Markdown、按阅读顺序排序的JSON、含有丰富信息的中间格式等
-- 支持多种可视化结果,包括layout可视化、span可视化等,便于高效确认输出效果与质检
+- 支持layout可视化,便于高效确认输出效果与质检
- 内置命令行、FastAPI、Gradio WebUI,支持本地编排和多服务部署
- 支持纯CPU环境运行,并支持 GPU/MPS加速,以及十余款国产算力平台的推理加速
- 兼容Windows、Linux和Mac平台
diff --git a/docs/en/index.md b/docs/en/index.md
index 6a77363f..ae6aa267 100644
--- a/docs/en/index.md
+++ b/docs/en/index.md
@@ -60,7 +60,7 @@ Compared to well-known commercial products domestically and internationally, Min
- Automatically detect scanned PDFs and garbled PDFs, and enable OCR functionality
- OCR supports detection and recognition of 109 languages
- Support multiple output formats, such as multimodal and NLP Markdown, reading-order-sorted JSON, and information-rich intermediate formats
-- Support multiple visualization results, including layout visualization, span visualization, etc., for efficient confirmation of output effects and quality inspection
+- Support layout visualization for efficient confirmation of output effects and quality inspection
- Built-in CLI, FastAPI, Gradio WebUI, for local orchestration and multi-service deployment
- Support pure CPU environment operation, and support GPU(CUDA)/NPU(CANN)/MPS acceleration
- Compatible with Windows, Linux and Mac platforms
diff --git a/docs/en/reference/output_files.md b/docs/en/reference/output_files.md
index 32e15640..a6ef518d 100644
--- a/docs/en/reference/output_files.md
+++ b/docs/en/reference/output_files.md
@@ -32,26 +32,6 @@ The following sections provide detailed descriptions of each file's purpose and
![layout page example](../images/layout_example.png)
-### Text Spans File (span.pdf)
-
-> [!NOTE]
-> Only generated when span visualization is explicitly enabled.
-
-**File naming format**: `{original_filename}_span.pdf`
-
-**Functionality**:
-
-- Uses different colored line boxes to annotate page content based on span type
-- Used for quality inspection and issue troubleshooting
-
-**Use cases**:
-
-- Quickly troubleshoot text loss issues
-- Check inline formula recognition
-- Verify text segmentation accuracy
-
-![span page example](../images/spans_example.png)
-
## Structured Data Files
> [!IMPORTANT]
@@ -452,7 +432,6 @@ The above files constitute MinerU's complete output results. Users can choose ap
- **Debugging and verification** (Use visualization files):
* layout.pdf
- * span.pdf
- **Content extraction**: (Use simplified files):
* *.md
diff --git a/docs/images/spans_example.png b/docs/images/spans_example.png
deleted file mode 100644
index 14de87ed..00000000
Binary files a/docs/images/spans_example.png and /dev/null differ
diff --git a/docs/zh/index.md b/docs/zh/index.md
index 2de2c659..6f3fbdb8 100644
--- a/docs/zh/index.md
+++ b/docs/zh/index.md
@@ -59,7 +59,7 @@ MinerU诞生于[书生-浦语](https://github.com/InternLM/InternLM)的预训练
- 自动检测扫描版PDF和乱码PDF,并启用OCR功能
- OCR支持109种语言的检测与识别
- 支持多种输出格式,如多模态与NLP的Markdown、按阅读顺序排序的JSON、含有丰富信息的中间格式等
-- 支持多种可视化结果,包括layout可视化、span可视化等,便于高效确认输出效果与质检
+- 支持layout可视化,便于高效确认输出效果与质检
- 内置命令行、FastAPI、Gradio WebUI,支持本地编排和多服务部署
- 支持纯CPU环境运行,并支持 GPU(CUDA)/NPU(CANN)/MPS 加速
- 兼容Windows、Linux和Mac平台
diff --git a/docs/zh/reference/output_files.md b/docs/zh/reference/output_files.md
index 0bd1de9a..d4e598bd 100644
--- a/docs/zh/reference/output_files.md
+++ b/docs/zh/reference/output_files.md
@@ -32,26 +32,6 @@
![layout 页面示例](../images/layout_example.png)
-### 文本片段文件 (span.pdf)
-
-> [!NOTE]
-> 仅在显式启用 span 可视化时生成。
-
-**文件命名格式**:`{原文件名}_span.pdf`
-
-**功能说明**:
-
-- 根据 span 类型使用不同颜色线框标注页面内容
-- 用于质量检查和问题排查
-
-**使用场景**:
-
-- 快速排查文本丢失问题
-- 检查行内公式识别情况
-- 验证文本分割准确性
-
-![span 页面示例](../images/spans_example.png)
-
## 结构化数据文件
> [!IMPORTANT]
@@ -481,7 +461,6 @@ schema 2.0 已移除旧字段 `preproc_blocks`/`para_blocks`/`page_size`/`images
- **调试和验证**(使用可视化文件):
* layout.pdf
- * span.pdf
- **内容提取**(使用简化文件):
* *.md
diff --git a/mineru/cli_old/client.py b/mineru/cli_old/client.py
index c9c0131d..cb8ad7b3 100644
--- a/mineru/cli_old/client.py
+++ b/mineru/cli_old/client.py
@@ -418,7 +418,6 @@ def build_visualization_jobs(
parse_method,
is_office=document.suffix in office_suffixes,
),
- draw_span=False,
)
for document in planned_task.documents
]
diff --git a/mineru/cli_old/common.py b/mineru/cli_old/common.py
index 1d4bc4cf..e0537499 100644
--- a/mineru/cli_old/common.py
+++ b/mineru/cli_old/common.py
@@ -19,7 +19,7 @@ from ..render import render_markdown, render_structured_content
from ..render.writer import FileBasedDataWriter
from ..types import MiddleJson, PageInfo
from ..utils.backend_options import DEFAULT_BACKEND, DEFAULT_HYBRID_EFFORT, LOCAL_HYBRID_EFFORT, resolve_backend_and_effort
-from ..utils.draw_bbox import draw_layout_bbox, draw_span_bbox
+from ..utils.draw_bbox import draw_layout_bbox
from ..utils.engine_utils import get_vlm_engine
from ..utils.guess_suffix_or_lang import guess_suffix_by_bytes
from ..utils.image_payload import ImagePayloadCache
@@ -243,7 +243,6 @@ def _process_output(
local_image_dir: str,
md_writer: Any,
f_draw_layout_bbox: bool,
- f_draw_span_bbox: bool,
f_dump_orig_pdf: bool,
f_dump_md: bool,
f_dump_content_list: bool,
@@ -266,12 +265,6 @@ def _process_output(
except Exception as exc:
logger.warning(f"Skipping layout bbox visualization for {pdf_file_name}: {exc}")
- if f_draw_span_bbox:
- try:
- draw_span_bbox(visualization_pages, pdf_bytes, local_md_dir, f"{pdf_file_name}_span.pdf")
- except Exception as exc:
- logger.warning(f"Skipping span bbox visualization for {pdf_file_name}: {exc}")
-
if f_dump_orig_pdf:
if process_mode in ["hybrid", "vlm"]:
md_writer.write(
@@ -355,7 +348,6 @@ def _process_hybrid(
parse_method: str,
backend: str,
f_draw_layout_bbox: bool,
- f_draw_span_bbox: bool,
f_dump_md: bool,
f_dump_middle_json: bool,
f_dump_model_output: bool,
@@ -381,7 +373,7 @@ def _process_hybrid(
md_writer = FileBasedDataWriter(local_md_dir)
image_cache = ImagePayloadCache()
- middle_json, infer_result, _vlm_ocr_enable = hybrid_doc_analyze(
+ middle_json, infer_result, _ = hybrid_doc_analyze(
pdf_bytes,
backend=backend,
parse_method=parse_method,
@@ -392,9 +384,6 @@ def _process_hybrid(
**kwargs,
)
- # f_draw_span_bbox = not _vlm_ocr_enable
- f_draw_span_bbox = False
-
_process_output(
middle_json,
pdf_bytes,
@@ -403,7 +392,6 @@ def _process_hybrid(
local_image_dir,
md_writer,
f_draw_layout_bbox,
- f_draw_span_bbox,
f_dump_orig_pdf,
f_dump_md,
f_dump_content_list,
@@ -427,7 +415,6 @@ async def _async_process_hybrid(
parse_method: str,
backend: str,
f_draw_layout_bbox: bool,
- f_draw_span_bbox: bool,
f_dump_md: bool,
f_dump_middle_json: bool,
f_dump_model_output: bool,
@@ -453,7 +440,7 @@ async def _async_process_hybrid(
md_writer = FileBasedDataWriter(local_md_dir)
image_cache = ImagePayloadCache()
- middle_json, infer_result, _vlm_ocr_enable = await aio_hybrid_doc_analyze(
+ middle_json, infer_result, _ = await aio_hybrid_doc_analyze(
pdf_bytes,
backend=backend,
parse_method=parse_method,
@@ -464,9 +451,6 @@ async def _async_process_hybrid(
**kwargs,
)
- # f_draw_span_bbox = not _vlm_ocr_enable
- f_draw_span_bbox = False
-
_process_output(
middle_json,
pdf_bytes,
@@ -475,7 +459,6 @@ async def _async_process_hybrid(
local_image_dir,
md_writer,
f_draw_layout_bbox,
- f_draw_span_bbox,
f_dump_orig_pdf,
f_dump_md,
f_dump_content_list,
@@ -520,7 +503,6 @@ def _process_office_doc(
)
f_draw_layout_bbox = False
- f_draw_span_bbox = False
_process_output(
middle_json,
@@ -530,7 +512,6 @@ def _process_office_doc(
local_image_dir,
md_writer,
f_draw_layout_bbox,
- f_draw_span_bbox,
f_dump_orig_file,
f_dump_md,
f_dump_content_list,
@@ -555,7 +536,6 @@ def do_parse(
parse_method: str = "auto",
server_url: str | None = None,
f_draw_layout_bbox: bool = True,
- f_draw_span_bbox: bool = True,
f_dump_md: bool = True,
f_dump_middle_json: bool = True,
f_dump_model_output: bool = True,
@@ -569,6 +549,8 @@ def do_parse(
client_side_output_generation: bool = False,
**kwargs: Any,
) -> None:
+ if "f_draw_span_bbox" in kwargs:
+ raise TypeError("f_draw_span_bbox is no longer supported because InlineSpan has no bbox")
backend, effort = resolve_backend_and_effort(backend, effort)
need_remove_index = _process_office_doc(
output_dir,
@@ -610,7 +592,6 @@ def do_parse(
parse_method,
backend,
f_draw_layout_bbox,
- f_draw_span_bbox,
f_dump_md,
f_dump_middle_json,
f_dump_model_output,
@@ -638,7 +619,6 @@ async def aio_do_parse(
parse_method: str = "auto",
server_url: str | None = None,
f_draw_layout_bbox: bool = True,
- f_draw_span_bbox: bool = True,
f_dump_md: bool = True,
f_dump_middle_json: bool = True,
f_dump_model_output: bool = True,
@@ -652,6 +632,8 @@ async def aio_do_parse(
client_side_output_generation: bool = False,
**kwargs: Any,
) -> None:
+ if "f_draw_span_bbox" in kwargs:
+ raise TypeError("f_draw_span_bbox is no longer supported because InlineSpan has no bbox")
backend, effort = resolve_backend_and_effort(backend, effort)
# Office 解析是同步且可能耗时的操作,异步入口需要放到线程中避免阻塞事件循环。
need_remove_index = await asyncio.to_thread(
@@ -695,7 +677,6 @@ async def aio_do_parse(
parse_method,
backend,
f_draw_layout_bbox,
- f_draw_span_bbox,
f_dump_md,
f_dump_middle_json,
f_dump_model_output,
diff --git a/mineru/cli_old/fast_api.py b/mineru/cli_old/fast_api.py
index 91207954..b723d224 100644
--- a/mineru/cli_old/fast_api.py
+++ b/mineru/cli_old/fast_api.py
@@ -836,7 +836,6 @@ async def run_parse_job(
image_analysis=request_options.image_analysis,
server_url=request_options.server_url,
f_draw_layout_bbox=False,
- f_draw_span_bbox=False,
f_dump_md=request_options.return_md,
f_dump_middle_json=request_options.return_middle_json,
f_dump_model_output=request_options.return_model_output,
diff --git a/mineru/cli_old/gradio_app.py b/mineru/cli_old/gradio_app.py
index 3eaa4690..e8d50953 100644
--- a/mineru/cli_old/gradio_app.py
+++ b/mineru/cli_old/gradio_app.py
@@ -1080,7 +1080,6 @@ def _generate_v1_gradio_layout_preview(
backend=backend,
parse_method="auto",
parse_dir=local_md_dir,
- draw_span=False,
)
)
if result.status != VISUALIZATION_FINISHED:
diff --git a/mineru/cli_old/visualization.py b/mineru/cli_old/visualization.py
index e0ccf302..dc2561c5 100644
--- a/mineru/cli_old/visualization.py
+++ b/mineru/cli_old/visualization.py
@@ -3,9 +3,9 @@ import json
from dataclasses import dataclass
from pathlib import Path
-from mineru.parser.base import ParseResult
-from mineru.types import PageInfo
-from mineru.utils.pdf_document import PDFDocument
+from ..model.flash.pdf.document import PDFDocument
+from ..parser.base import ParseResult
+from ..types import PageInfo
VISUALIZATION_FINISHED = "finished"
VISUALIZATION_SKIPPED = "skipped"
@@ -17,7 +17,6 @@ class VisualizationJob:
backend: str
parse_method: str
parse_dir: Path
- draw_span: bool
@dataclass(frozen=True)
@@ -37,11 +36,7 @@ def select_pages_for_pdf_visualization(
if retained_page_indices is None:
return pages
pages_by_original_index = {page.page_idx: page for page in pages}
- return [
- pages_by_original_index[page_idx]
- for page_idx in retained_page_indices
- if page_idx in pages_by_original_index
- ]
+ return [pages_by_original_index[page_idx] for page_idx in retained_page_indices if page_idx in pages_by_original_index]
def run_visualization_job(job: VisualizationJob) -> VisualizationResult:
@@ -91,9 +86,6 @@ def run_visualization_job(job: VisualizationJob) -> VisualizationResult:
doc = PDFDocument(pdf_bytes)
generated_files = [f"{job.document_stem}_layout.pdf"]
doc.draw_layout_bbox(pages, str(job.parse_dir / generated_files[0]))
- if job.draw_span:
- generated_files.append(f"{job.document_stem}_span.pdf")
- doc.draw_span_bbox(pages, str(job.parse_dir / generated_files[1]))
except Exception as exc:
return VisualizationResult(
document_stem=job.document_stem,
diff --git a/mineru/model/flash/pdf/diagnostics.py b/mineru/model/flash/pdf/diagnostics.py
index 9de7f9a6..021e860b 100644
--- a/mineru/model/flash/pdf/diagnostics.py
+++ b/mineru/model/flash/pdf/diagnostics.py
@@ -9,7 +9,7 @@ from loguru import logger
from pypdf import PageObject, PdfReader, PdfWriter
from reportlab.pdfgen import canvas
-from ....types import BBox, RAW_PHONETIC, Block, BlockType, ContentType, PageInfo, Span
+from ....types import BBox, RAW_PHONETIC, Block, BlockType, PageInfo
# 文本类 block 共用 text bbox 样式,避免新增文本形态时遗漏多个绘制入口。
TEXT_LIKE_BLOCK_TYPES_FOR_BBOX = {
@@ -27,9 +27,6 @@ DIRECT_LAYOUT_BBOX_BLOCK_TYPES = TEXT_LIKE_BLOCK_TYPES_FOR_BBOX | {
BlockType.INDEX,
}
-# span.pdf 从这些结构性 block 中收集内部 span bbox。
-SPAN_SOURCE_BLOCK_TYPES = DIRECT_LAYOUT_BBOX_BLOCK_TYPES
-
def _get_layout_source_blocks(page: PageInfo) -> list[Block]:
"""获取 layout.pdf 的页内原始布局块,避免段落合并后跨页子项串页绘制。"""
@@ -336,106 +333,6 @@ def draw_layout_bbox(
output_pdf.write(f)
-def draw_span_bbox(
- pages: list[PageInfo],
- pdf_bytes: bytes,
- out_path: str,
- filename: str,
-) -> None:
- text_list = []
- inline_equation_list = []
- interline_equation_list = []
- image_list = []
- table_list = []
- dropped_list = []
-
- def get_span_info(span: Span) -> None: # noqa: ANN202
- if span.type == ContentType.TEXT:
- page_text_list.append(span.bbox)
- elif span.type == ContentType.INLINE_EQUATION:
- page_inline_equation_list.append(span.bbox)
- elif span.type == ContentType.INTERLINE_EQUATION:
- page_interline_equation_list.append(span.bbox)
- elif span.type in [ContentType.IMAGE, ContentType.CHART]:
- page_image_list.append(span.bbox)
- elif span.type == ContentType.TABLE:
- page_table_list.append(span.bbox)
-
- for page in pages:
- page_text_list = []
- page_inline_equation_list = []
- page_interline_equation_list = []
- page_image_list = []
- page_table_list = []
- page_dropped_list = []
-
- # 构造dropped_list
- for block in page.discarded_blocks:
- for line in block.lines:
- for span in line.spans:
- page_dropped_list.append(span.bbox)
- dropped_list.append(page_dropped_list)
- # 构造其余useful_list
- # for block in page.para_blocks: # span直接用分段合并前的结果就可以
- for block in page.preproc_blocks:
- if block.type in SPAN_SOURCE_BLOCK_TYPES:
- for line in block.lines:
- for span in line.spans:
- get_span_info(span)
- elif block.type in [BlockType.IMAGE, BlockType.TABLE, BlockType.CHART, BlockType.CODE]:
- for sub_block in block.blocks:
- for line in sub_block.lines:
- for span in line.spans:
- get_span_info(span)
- text_list.append(page_text_list)
- inline_equation_list.append(page_inline_equation_list)
- interline_equation_list.append(page_interline_equation_list)
- image_list.append(page_image_list)
- table_list.append(page_table_list)
-
- pdf_bytes_io = BytesIO(pdf_bytes)
- pdf_docs = PdfReader(pdf_bytes_io)
- output_pdf = PdfWriter()
-
- for i, page in enumerate(pdf_docs.pages):
- # 获取原始页面尺寸
- page_width, page_height = float(page.cropbox[2]), float(page.cropbox[3])
- custom_page_size = (page_width, page_height)
-
- packet = BytesIO()
- # 使用原始PDF的尺寸创建canvas
- c = canvas.Canvas(packet, pagesize=custom_page_size)
-
- # 获取当前页面的数据
- draw_bbox_without_number(i, text_list, page, c, [255, 0, 0], False)
- draw_bbox_without_number(i, inline_equation_list, page, c, [0, 255, 0], False)
- draw_bbox_without_number(i, interline_equation_list, page, c, [0, 0, 255], False)
- draw_bbox_without_number(i, image_list, page, c, [255, 204, 0], False)
- draw_bbox_without_number(i, table_list, page, c, [204, 0, 255], False)
- draw_bbox_without_number(i, dropped_list, page, c, [158, 158, 158], False)
-
- c.save()
- packet.seek(0)
- overlay_pdf = PdfReader(packet)
-
- # 添加检查确保overlay_pdf.pages不为空
- if len(overlay_pdf.pages) > 0:
- new_page = PageObject(pdf=None)
- new_page.update(page)
- page = new_page
- page.merge_page(overlay_pdf.pages[0])
- else:
- # 记录日志并继续处理下一个页面
- # logger.warning(f"span.pdf: 第{i + 1}页未能生成有效的overlay PDF")
- pass
-
- output_pdf.add_page(page)
-
- # Save the PDF
- with open(f"{out_path}/{filename}", "wb") as f:
- output_pdf.write(f)
-
-
if __name__ == "__main__":
# 读取PDF文件
pdf_path = "examples/demo1.pdf"
diff --git a/mineru/model/flash/pdf/document.py b/mineru/model/flash/pdf/document.py
index 378af574..b78c4a42 100644
--- a/mineru/model/flash/pdf/document.py
+++ b/mineru/model/flash/pdf/document.py
@@ -551,13 +551,6 @@ class PDFDocument:
filename = os.path.basename(output_path)
draw_layout_bbox(pages, self._pdf_bytes, out_dir, filename)
- def draw_span_bbox(self, pages: list[PageInfo], output_path: str) -> None:
- from .diagnostics import draw_span_bbox
-
- out_dir = os.path.dirname(output_path) or "."
- filename = os.path.basename(output_path)
- draw_span_bbox(pages, self._pdf_bytes, out_dir, filename)
-
# ------------------------------------------------------------------ #
# Internal
# ------------------------------------------------------------------ #
diff --git a/tests/unittest/test_pdf_document.py b/tests/unittest/test_pdf_document.py
index e7eacb0c..78475af1 100644
--- a/tests/unittest/test_pdf_document.py
+++ b/tests/unittest/test_pdf_document.py
@@ -23,6 +23,12 @@ from reportlab.pdfgen.canvas import Canvas
from mineru.model.flash.pdf import document as pdf_document
+def test_pdf_document_does_not_expose_span_bbox_visualization() -> None:
+ """验证公开 PDFDocument 不再暴露无法支持的 span bbox 绘制接口。"""
+
+ assert not hasattr(pdf_document.PDFDocument, "draw_span_bbox")
+
+
def test_pdf_page_exposes_path_infos_without_raw_pdfium_access() -> None:
"""验证 PDFPage 只读代理当前页 Path 摘要并保留页索引。"""