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

Method pdfocr_tobytes

src/__init__.py:13717–13736  ·  view source on GitHub ↗

Save pixmap as an OCR-ed PDF page. Args: compress: (bool) compress, default 1 (True). language: (str) language(s) occurring on page, default "eng" (English), multiples like "eng+ger" for English and German. tessdata: (str) folder name

(self, compress=True, language="eng", tessdata=None)

Source from the content-addressed store, hash-verified

13715 out.fz_close_output() # Avoid MuPDF warning.
13716
13717 def pdfocr_tobytes(self, compress=True, language="eng", tessdata=None):
13718 """Save pixmap as an OCR-ed PDF page.
13719
13720 Args:
13721 compress: (bool) compress, default 1 (True).
13722 language: (str) language(s) occurring on page, default "eng" (English),
13723 multiples like "eng+ger" for English and German.
13724 tessdata: (str) folder name of Tesseract's language support. If None
13725 we use environment variable TESSDATA_PREFIX or search for
13726 Tesseract installation.
13727 Notes:
13728 On failure, make sure Tesseract is installed and you have set
13729 <tessdata> or environment variable "TESSDATA_PREFIX" to the folder
13730 containing your Tesseract&#x27;s language support data.
13731 """
13732 tessdata = get_tessdata(tessdata)
13733 from io import BytesIO
13734 bio = BytesIO()
13735 self.pdfocr_save(bio, compress=compress, language=language, tessdata=tessdata)
13736 return bio.getvalue()
13737
13738 def pil_image(self):
13739 """Create a Pillow Image from the Pixmap."""

Callers 4

get_textpage_ocrFunction · 0.95
get_textpage_ocrFunction · 0.95
full_ocrFunction · 0.80
full_ocrFunction · 0.80

Calls 2

pdfocr_saveMethod · 0.95
get_tessdataFunction · 0.85

Tested by

no test coverage detected