Skip to content

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

Fix suffix identification for AI files to correctly handle PDF extensions

myhloli2c356ccceea7
diff --git a/mineru/cli/common.py b/mineru/cli/common.py
index 98453f4f..ae89de3d 100644
--- a/mineru/cli/common.py
+++ b/mineru/cli/common.py
@@ -27,6 +27,8 @@ def read_fn(path):
with open(str(path), "rb") as input_file:
file_bytes = input_file.read()
file_suffix = guess_suffix_by_bytes(file_bytes)
+ if file_suffix in ["ai"] and path.suffix in [".pdf"]:
+ file_suffix = "pdf"
if file_suffix in image_suffixes:
return images_bytes_to_pdf_bytes(file_bytes)
elif file_suffix in pdf_suffixes:
diff --git a/mineru/utils/guess_suffix_or_lang.py b/mineru/utils/guess_suffix_or_lang.py
index a3556b34..887aa190 100644
--- a/mineru/utils/guess_suffix_or_lang.py
+++ b/mineru/utils/guess_suffix_or_lang.py
@@ -1,3 +1,5 @@
+from pathlib import Path
+
from magika import Magika
@@ -16,5 +18,9 @@ def guess_suffix_by_bytes(file_bytes) -> str:
def guess_suffix_by_path(file_path) -> str:
+ if not isinstance(file_path, Path):
+ file_path = Path(file_path)
suffix = magika.identify_path(file_path).prediction.output.label
+ if suffix in ["ai"] and file_path.suffix in [".pdf"]:
+ suffix = "pdf"
return suffix
\ No newline at end of file