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
fix: improve PDF suffix detection by checking PDF signature bytes
myhloli8d1866ab9f79
diff --git a/mineru/utils/guess_suffix_or_lang.py b/mineru/utils/guess_suffix_or_lang.pyindex 0fabc343..67974ea7 100644--- a/mineru/utils/guess_suffix_or_lang.py+++ b/mineru/utils/guess_suffix_or_lang.py@@ -4,6 +4,7 @@ from magika import MagikaDEFAULT_LANG = "txt"+PDF_SIG_BYTES = b'%PDF'magika = Magika()def guess_language_by_text(code):@@ -14,7 +15,7 @@ def guess_language_by_text(code):def guess_suffix_by_bytes(file_bytes, file_path=None) -> str:suffix = magika.identify_bytes(file_bytes).prediction.output.label- if file_path and suffix in ["ai", "html"] and Path(file_path).suffix.lower() in [".pdf"]:+ if file_path and suffix in ["ai", "html"] and Path(file_path).suffix.lower() in [".pdf"] and file_bytes[:4] == PDF_SIG_BYTES:suffix = "pdf"return suffix@@ -24,5 +25,10 @@ def guess_suffix_by_path(file_path) -> str:file_path = Path(file_path)suffix = magika.identify_path(file_path).prediction.output.labelif suffix in ["ai", "html"] and file_path.suffix.lower() in [".pdf"]:- suffix = "pdf"+ try:+ with open(file_path, 'rb') as f:+ if f.read(4) == PDF_SIG_BYTES:+ suffix = "pdf"+ except Exception:+ passreturn suffix\ No newline at end of file