MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / extract_text_from_pdf

Function extract_text_from_pdf

skills/pdf-parser/scripts/parse_pdf.py:487–506  ·  view source on GitHub ↗

从 PDF 提取文本

(pdf_path: str)

Source from the content-addressed store, hash-verified

485
486
487def extract_text_from_pdf(pdf_path: str) -> str:
488 """从 PDF 提取文本"""
489 pdf_file = Path(pdf_path)
490 if not pdf_file.exists():
491 raise FileNotFoundError(f"PDF not found: {pdf_path}")
492
493 primary_text = ""
494 if HAS_PYMUPDF:
495 primary_text = _extract_text_from_pdf_with_pymupdf(pdf_path)
496 elif HAS_PDFPLUMBER:
497 primary_text = _extract_text_from_pdf_with_pdfplumber(pdf_path)
498 else:
499 raise ImportError("No PDF library available. Install pymupdf or pdfplumber.")
500
501 if _should_try_ocr(primary_text, pdf_path):
502 ocr_text = _extract_text_from_pdf_with_ocr(pdf_path)
503 if (not primary_text and ocr_text) or len(ocr_text) > len(primary_text) + 80:
504 return ocr_text
505
506 return primary_text
507
508
509def extract_metadata(text: str) -> Dict:

Callers 1

parse_pdfFunction · 0.85

Tested by

no test coverage detected