(page, dpi, language, flags)
| 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: |
no test coverage detected
searching dependent graphs…