(page: Any)
| 285 | |
| 286 | |
| 287 | def _ocr_page_with_pytesseract(page: Any) -> str: |
| 288 | if not (HAS_PIL and HAS_PYTESSERACT): |
| 289 | return "" |
| 290 | |
| 291 | scale = max(1.0, float(PDF_PARSER_OCR_DPI) / 72.0) |
| 292 | pix = page.get_pixmap(matrix=fitz.Matrix(scale, scale), alpha=False) |
| 293 | mode = "RGB" if pix.n < 4 else "RGBA" |
| 294 | try: |
| 295 | image = Image.frombytes(mode, [pix.width, pix.height], pix.samples) |
| 296 | return str(pytesseract.image_to_string(image, lang=PDF_PARSER_OCR_LANG) or "").strip() |
| 297 | except Exception: |
| 298 | return "" |
| 299 | |
| 300 | |
| 301 | def _ocr_page_with_pymupdf_ocr(page: Any) -> str: |
no outgoing calls
no test coverage detected