From 61b05b3dee4fa8ac6371c72bcb6237850aa6b905 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Thu, 13 Oct 2016 13:15:27 -0700 Subject: [PATCH] Fix issue: BitsPerComponent is an optional field, sometimes omitted --- ocrmypdf/pageinfo.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ocrmypdf/pageinfo.py b/ocrmypdf/pageinfo.py index b17b1594..e5a2af66 100644 --- a/ocrmypdf/pageinfo.py +++ b/ocrmypdf/pageinfo.py @@ -211,7 +211,10 @@ def _find_page_inline_images(page, pageinfo, contentsinfo): image['name'] = str('inline-%02d' % n) image['width'] = inline.settings['/W'] image['height'] = inline.settings['/H'] - image['bpc'] = inline.settings['/BPC'] + if '/BPC' in inline.settings['/BPC'] + image['bpc'] = inline.settings['/BPC'] + else: + image['bpc'] = 8 image['color'] = FRIENDLY_COLORSPACE.get(inline.settings['/CS'], '-') image['comp'] = FRIENDLY_COMP.get(image['color'], '?') if '/F' in inline.settings: @@ -244,7 +247,10 @@ def _find_page_regular_images(page, pageinfo, contentsinfo): image['name'] = str(xobj) image['width'] = pdfimage['/Width'] image['height'] = pdfimage['/Height'] - image['bpc'] = pdfimage['/BitsPerComponent'] + if '/BitsPerComponent' in pdfimage: + image['bpc'] = pdfimage['/BitsPerComponent'] + else: + image['bpc'] = 8 # Fixme: this is incorrectly treats explicit masks as stencil masks, # but good enough for now. Explicit masks have /ImageMask true but are