r/programminghelp • u/ShimadaShimado • Dec 31 '19
Python Getting images from a PDF
Hi, I'm trying to extract images from a PDF using minecart.
This is the code i have-
I am getting an index out of range error on the second to last line. There is an image on the first page of the pdf.
What's wrong?
import minecart
pdffile = open('test.pdf', 'rb')
doc = minecart.Document(pdffile)
page = doc.get_page(0)
for page in doc.iter_pages():
im = page.images[0].as_pil() # requires pillow
display(im)
5
Upvotes
4
u/marko312 Jan 01 '20
Does every page have an image?
There is something weird going on in the provided code - you initially set
pageto the first page of the document:but then proceed to iterate over all the pages with the same variable:
Maybe you meant to omit the loop?