From f0f6b57c8712260ff45ac1340a116f648d3950bd Mon Sep 17 00:00:00 2001 From: Jim Barlow Date: Sun, 8 Feb 2015 17:38:27 -0800 Subject: [PATCH] When deciding on OCR, check for presence of text rather than a font It appears to be possible to have a PDF with an embedded font that is either unused or used only for whitespace. So check for some amount of actual text instead. --- src/ocrpage.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ocrpage.py b/src/ocrpage.py index 8e774264..7cf48363 100755 --- a/src/ocrpage.py +++ b/src/ocrpage.py @@ -90,12 +90,13 @@ def pdf_get_pageinfo(infile, page, width_pt, height_pt): pageinfo['height_inches'] = height_pt / 72.0 pageinfo['images'] = [] - p_pdffonts = Popen(['pdffonts', '-f', str(page), '-l', str(page), infile], - close_fds=True, stdout=PIPE, stderr=PIPE, - universal_newlines=True) - pdffonts, _ = p_pdffonts.communicate() - if len(pdffonts.splitlines()) > 2: - logger.info("Page already contains font data!") + p_pdftotext = Popen(['pdftotext', '-f', str(page), '-l', str(page), + '-raw', '-nopgbrk', infile, '-'], + close_fds=True, stdout=PIPE, stderr=PIPE, + 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