From bece4c3e024c91d8bb35d5d4d334a07cf848db6e Mon Sep 17 00:00:00 2001 From: Jim Barlow Date: Sun, 8 Feb 2015 19:51:18 -0800 Subject: [PATCH] Describe what decision was made based on -f and -s and presence of text --- src/ocrpage.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/ocrpage.py b/src/ocrpage.py index 7cf48363..bff8ea30 100755 --- a/src/ocrpage.py +++ b/src/ocrpage.py @@ -96,7 +96,6 @@ def pdf_get_pageinfo(infile, page, width_pt, height_pt): universal_newlines=True) text, _ = p_pdftotext.communicate() if len(text.strip()) > 0: - logger.info("Page already contains text!") pageinfo['has_text'] = True else: pageinfo['has_text'] = False @@ -133,6 +132,24 @@ def pdf_get_pageinfo(infile, page, width_pt, height_pt): pageno, width_pt, height_pt = map(int, options.page_info.split(' ', 3)) pageinfo = pdf_get_pageinfo(options.input_pdf, pageno, width_pt, height_pt) +with logger_mutex: + if pageinfo['has_text']: + s = "Page {0} already has text! – {1}" + + if not options.force_ocr and not options.skip_text: + logger.error(s.format(pageno, + "aborting (use -f or -s to force OCR)")) + sys.exit(1) + elif options.force_ocr: + logger.info(s.format(pageno, + "rasterizing text and running OCR anyway")) + elif options.skip_text: + logger.info(s.format(pageno, + "skipping all processing on this page")) + +ocr_required = not (pageinfo['has_text'] and options.skip_text != 0) or \ + options.force_ocr != 0 + def re_symlink(input_file, soft_link_name, logger, logger_mutex): """ @@ -178,9 +195,6 @@ def setup_working_directory(input_file, soft_link_name): pass -ocr_required = not (pageinfo['has_text'] and options.skip_text != 0) - - @active_if(not ocr_required) @transform(setup_working_directory, formatter(),