(text: str, pdf_path: str)
| 220 | |
| 221 | |
| 222 | def _should_try_ocr(text: str, pdf_path: str) -> bool: |
| 223 | if not PDF_PARSER_ENABLE_OCR or not HAS_PYMUPDF: |
| 224 | return False |
| 225 | |
| 226 | normalized = clean_extracted_text(text) |
| 227 | if len(normalized) < PDF_PARSER_OCR_MIN_TEXT_CHARS: |
| 228 | return True |
| 229 | |
| 230 | try: |
| 231 | doc = fitz.open(pdf_path) |
| 232 | try: |
| 233 | page_count = max(1, len(doc)) |
| 234 | finally: |
| 235 | doc.close() |
| 236 | except Exception: |
| 237 | page_count = 1 |
| 238 | |
| 239 | avg_chars_per_page = len(normalized) / max(page_count, 1) |
| 240 | if avg_chars_per_page < max(40, PDF_PARSER_OCR_MIN_TEXT_CHARS // 2): |
| 241 | return True |
| 242 | |
| 243 | return False |
| 244 | |
| 245 | |
| 246 | def _render_page_to_numpy(page: Any): |
no test coverage detected