From 0b012697e54531110de0bd55fb304dce7fde4920 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Wed, 26 Jul 2017 21:00:13 -0700 Subject: [PATCH] Whitelist the Latin-1 languages that work with HOCR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Omitted French because the rare 'oe' and 'ΓΏ' glyphs are not in Latin-1. Basically steer people away from HOCR renderer but avoid a potential disruptive behavior change. --- ocrmypdf/__main__.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/ocrmypdf/__main__.py b/ocrmypdf/__main__.py index f9eddc49..3c3d571a 100755 --- a/ocrmypdf/__main__.py +++ b/ocrmypdf/__main__.py @@ -41,6 +41,9 @@ warnings.simplefilter('ignore', pypdf.utils.PdfReadWarning) MINIMUM_TESS_VERSION = '3.04' +HOCR_OK_LANGS = frozenset([ + 'eng', 'deu', 'spa', 'ita', 'por' +]) def complain(message): print(*textwrap.wrap(message), file=sys.stderr) @@ -395,12 +398,20 @@ def check_options_ocr_behavior(options, log): # raise argparse.ArgumentError( # "Error: --redo-ocr and other OCR options are incompatible.") - if set(options.language) & {'chi_sim', 'chi_tra'} and \ - (options.pdf_renderer == 'hocr' or options.output_type == 'pdfa'): - log.warning( - "Your settings are known to cause problems with OCR of Chinese text. " - "Try adding these arguments: " - " ocrmypdf --pdf-renderer tesseract --output-type pdf") + if options.pdf_renderer == 'hocr' and \ + not set(options.language).issubset(HOCR_OK_LANGS): + msg = ( + "The 'hocr' PDF renderer is known to cause problems with one " + "or more of the languages in your document. ") + + if tesseract.has_textonly_pdf(): + msg += ( + "Use --pdf-renderer auto (the default) to avoid this issue.") + else: + msg += ( + "Use --pdf-renderer tesseract --output-type pdf to avoid " + "this issue") + log.warning(msg) def check_options_advanced(options, log):