diff --git a/pdfminer/image.py b/pdfminer/image.py index 34f27adf..56e6630b 100644 --- a/pdfminer/image.py +++ b/pdfminer/image.py @@ -71,10 +71,13 @@ def export_image(self, image): stream = image.stream filters = stream.get_filters() (width, height) = image.srcsize + colorspace = image.colorspace + if isinstance(colorspace, list): + colorspace = colorspace[0] if len(filters) == 1 and filters[0][0] in LITERALS_DCT_DECODE: ext = '.jpg' elif (image.bits == 1 or - image.bits == 8 and image.colorspace in (LITERAL_DEVICE_RGB, LITERAL_DEVICE_GRAY)): + image.bits == 8 and colorspace in (LITERAL_DEVICE_RGB, LITERAL_DEVICE_GRAY)): ext = '.%dx%d.bmp' % (width, height) else: ext = '.%d.%dx%d.img' % (image.bits, width, height) @@ -82,8 +85,8 @@ def export_image(self, image): path = os.path.join(self.outdir, name) with open(path, 'wb') as fp: if ext == '.jpg': - raw_data = stream.get_rawdata() - if LITERAL_DEVICE_CMYK in image.colorspace: + raw_data = stream.get_data() + if colorspace is LITERAL_DEVICE_CMYK: from PIL import Image from PIL import ImageChops ifp = BytesIO(raw_data) @@ -101,7 +104,7 @@ def export_image(self, image): for y in range(height): bmp.write_line(y, data[i:i+width]) i += width - elif image.bits == 8 and image.colorspace is LITERAL_DEVICE_RGB: + elif image.bits == 8 and colorspace is LITERAL_DEVICE_RGB: bmp = BMPWriter(fp, 24, width, height) data = stream.get_data() i = 0 @@ -109,7 +112,7 @@ def export_image(self, image): for y in range(height): bmp.write_line(y, data[i:i+width]) i += width - elif image.bits == 8 and image.colorspace is LITERAL_DEVICE_GRAY: + elif image.bits == 8 and colorspace is LITERAL_DEVICE_GRAY: bmp = BMPWriter(fp, 8, width, height) data = stream.get_data() i = 0 diff --git a/pdfminer/pdfdocument.py b/pdfminer/pdfdocument.py index 86ab7e97..337b9663 100644 --- a/pdfminer/pdfdocument.py +++ b/pdfminer/pdfdocument.py @@ -348,7 +348,7 @@ def compute_u(self, key): def compute_encryption_key(self, password): # Algorithm 3.2 - password = (password + self.PASSWORD_PADDING)[:32] # 1 + password = (password.encode('ascii') + self.PASSWORD_PADDING)[:32] # 1 hash = md5.md5(password) # 2 hash.update(self.o) # 3 hash.update(struct.pack('