Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions pdfminer/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,22 @@ 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)
name = image.name+ext
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)
Expand All @@ -101,15 +104,15 @@ 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
width = width*3
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
Expand Down
2 changes: 1 addition & 1 deletion pdfminer/pdfdocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<l', self.p)) # 4
Expand Down
2 changes: 1 addition & 1 deletion pdfminer/pdftypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def get_filters(self):
params = [params]*len(filters)
if STRICT and len(params) != len(filters):
raise PDFException("Parameters len filter mismatch")
return zip(filters, params)
return list(zip(filters, params))

def decode(self):
assert self.data is None and self.rawdata is not None
Expand Down