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

Function _ocr_page_with_pytesseract

skills/pdf-parser/scripts/parse_pdf.py:287–298  ·  view source on GitHub ↗
(page: Any)

Source from the content-addressed store, hash-verified

285
286
287def _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
301def _ocr_page_with_pymupdf_ocr(page: Any) -> str:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected