Using the code I found in this post, which corrects this example code, I'm trying to extract images on all pages of a PDF file. Now I'm getting an error for PNG images (works for JPG) at the second line of this piece (Image.frombytes
):
if xObject[obj]['/Filter'] == '/FlateDecode':
img = Image.frombytes(mode, size, data)
img.save(imagename + ".png")
number += 1
This yields ValueError: not enough image data
, which seems to occur because data
cannot be correctly decoded.