Skip to content

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

feat: add compatibility function for PDFium page object bounds and update dependency version constraint

myhloli53e2fd51d107
diff --git a/mineru/utils/pdf_classify.py b/mineru/utils/pdf_classify.py
index 29b5b6af..9d23006e 100644
--- a/mineru/utils/pdf_classify.py
+++ b/mineru/utils/pdf_classify.py
@@ -659,6 +659,19 @@ def _resolve_pdf_object(obj: Any) -> Any:
return obj
+def _get_pdfium_page_object_bounds(page_object: Any) -> tuple[float, float, float, float]:
+ """兼容 pypdfium2 4.x/5.x,统一获取页面对象的边界坐标。"""
+ get_bounds = getattr(page_object, "get_bounds", None)
+ if callable(get_bounds):
+ return get_bounds()
+
+ get_pos = getattr(page_object, "get_pos", None)
+ if callable(get_pos):
+ return get_pos()
+
+ raise AttributeError("PDFium page object has neither get_bounds() nor get_pos()")
+
+
def get_high_image_coverage_ratio_pdfium(pdf_doc: pdfium.PdfDocument, page_indices: list[int]) -> float:
high_image_coverage_pages = 0
@@ -673,7 +686,7 @@ def get_high_image_coverage_ratio_pdfium(pdf_doc: pdfium.PdfDocument, page_indic
for page_object in page.get_objects(filter=[pdfium_c.FPDF_PAGEOBJ_IMAGE], max_depth=3):
try:
- left, bottom, right, top = page_object.get_pos()
+ left, bottom, right, top = _get_pdfium_page_object_bounds(page_object)
image_area += max(0.0, right - left) * max(0.0, top - bottom)
finally:
close_pdfium_child(page_object)
diff --git a/pyproject.toml b/pyproject.toml
index 070c9032..25a6de4c 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -38,7 +38,7 @@ dependencies = [
"requests",
"httpx",
"pillow>=11.0.0",
- "pypdfium2>=4.30.0",
+ "pypdfium2>=4.30.0,<6.0.0",
"pypdf>=5.6.0",
"PyYAML>=6.0.1,<7",
"reportlab",