From a4702bff22d24c38063030ab1be43d72522bcee1 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Thu, 13 Aug 2015 23:10:22 -0700 Subject: [PATCH] Possible fix for issue #111 --- ocrmypdf/pageinfo.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ocrmypdf/pageinfo.py b/ocrmypdf/pageinfo.py index 81231653..499ad7e7 100644 --- a/ocrmypdf/pageinfo.py +++ b/ocrmypdf/pageinfo.py @@ -41,8 +41,14 @@ def _page_has_inline_images(page): # PDF always uses \r\n for separator regardless of platform # Really basic heuristic that might trigger the odd false positive # This is only finds the first image and is not quite spec compliant - contents = page.getContents() - data = contents.getData() + try: + contents = page.getContents() + data = contents.getData() + except AttributeError: + # If we can't access the contents or data (empty page?) then there + # are no inline images + return False + begin_image, image_data, end_image = False, False, False for data in re.split(b'\s+', data): if data == b'BI': @@ -53,6 +59,7 @@ def _page_has_inline_images(page): end_image = True if all((begin_image, image_data, end_image)): return True + return False def _find_page_images(page, pageinfo):