Skip to content

Commit

Permalink
src/__init__.py: avoid MuPDF warnings if tesseract fails.
Browse files Browse the repository at this point in the history
We need to always close FzOutput, otherwise MuPDF warns about dropping an
unclosed fz_output.
  • Loading branch information
julian-smith-artifex-com committed Dec 3, 2024
1 parent cf77f73 commit d587f8f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10316,8 +10316,10 @@ def pdfocr_save(self, filename, compress=1, language=None, tessdata=None):
mupdf.fz_save_pixmap_as_pdfocr( pix, filename, 0, opts)
else:
out = JM_new_output_fileptr( filename)
mupdf.fz_write_pixmap_as_pdfocr( out, pix, opts)
out.fz_close_output()
try:
mupdf.fz_write_pixmap_as_pdfocr( out, pix, opts)
finally:
out.fz_close_output() # Avoid MuPDF warning.

def pdfocr_tobytes(self, compress=True, language="eng", tessdata=None):
"""Save pixmap as an OCR-ed PDF page.
Expand Down

0 comments on commit d587f8f

Please sign in to comment.