MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / full_ocr

Function full_ocr

src_classic/utils.py:630–645  ·  view source on GitHub ↗
(page, dpi, language, flags)

Source from the content-addressed store, hash-verified

628 raise RuntimeError("No OCR support: TESSDATA_PREFIX not set")
629
630 def full_ocr(page, dpi, language, flags):
631 zoom = dpi / 72
632 mat = Matrix(zoom, zoom)
633 pix = page.get_pixmap(matrix=mat)
634 ocr_pdf = Document(
635 "pdf",
636 pix.pdfocr_tobytes(compress=False, language=language, tessdata=tessdata),
637 )
638 ocr_page = ocr_pdf.load_page(0)
639 unzoom = page.rect.width / ocr_page.rect.width
640 ctm = Matrix(unzoom, unzoom) * page.derotation_matrix
641 tpage = ocr_page.get_textpage(flags=flags, matrix=ctm)
642 ocr_pdf.close()
643 pix = None
644 tpage.parent = weakref.proxy(page)
645 return tpage
646
647 # if OCR for the full page, OCR its pixmap @ desired dpi
648 if full is True:

Callers 1

get_textpage_ocrFunction · 0.70

Calls 7

load_pageMethod · 0.95
closeMethod · 0.95
MatrixClass · 0.85
DocumentClass · 0.85
pdfocr_tobytesMethod · 0.80
get_pixmapMethod · 0.45
get_textpageMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…