From 98a3fda1f51db1b4140af25291bf88f25d7e37d9 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Mon, 3 Jun 2019 01:39:41 -0700 Subject: [PATCH] Drop support for Tesseract 4 alpha releases without textonly_pdf (mostly) hocr renderer can still be used --- src/ocrmypdf/_validation.py | 12 +++++++++++- src/ocrmypdf/_weave.py | 10 ---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ocrmypdf/_validation.py b/src/ocrmypdf/_validation.py index 2770874a..eacff184 100644 --- a/src/ocrmypdf/_validation.py +++ b/src/ocrmypdf/_validation.py @@ -106,6 +106,14 @@ def check_options_output(options): if options.pdf_renderer == 'auto': options.pdf_renderer = 'sandwich' + if options.pdf_renderer == 'sandwich' and not tesseract.has_textonly_pdf( + options.tesseract_env + ): + raise MissingDependencyError( + "You are using an alpha version of Tesseract 4.0 that does not support " + "the textonly_pdf parameter. We don't support versions this old." + ) + if options.output_type == 'pdfa': options.output_type = 'pdfa-2' @@ -216,7 +224,9 @@ def check_options_advanced(options): "--pdfa-image-compression argument has no effect when " "--output-type is not 'pdfa', 'pdfa-1', or 'pdfa-2'" ) - if tesseract.v4() and (options.user_words or options.user_patterns): + if tesseract.v4(options.tesseract_env) and ( + options.user_words or options.user_patterns + ): log.warning('Tesseract 4.x ignores --user-words, so this has no effect') diff --git a/src/ocrmypdf/_weave.py b/src/ocrmypdf/_weave.py index ac989a72..c9f64963 100644 --- a/src/ocrmypdf/_weave.py +++ b/src/ocrmypdf/_weave.py @@ -103,16 +103,6 @@ def _weave_layers_graft( pdf_text = pikepdf.open(text) pdf_text_contents = pdf_text.pages[0].Contents.read_bytes() - if not tesseract.has_textonly_pdf(): - # If we don't have textonly_pdf, edit the stream to delete the - # instruction to draw the image Tesseract generated, which we do not - # use. - stream = bytearray(pdf_text_contents) - pattern = b'/Im1 Do' - idx = stream.find(pattern) - stream[idx : (idx + len(pattern))] = b' ' * len(pattern) - pdf_text_contents = bytes(stream) - base_page = pdf_base.pages.p(page_num) # The text page always will be oriented up by this stage but the original