-
Notifications
You must be signed in to change notification settings - Fork 678
Closed
Description
doc = fitz.open("file.pdf")
for i in range(len(doc)):
for img in doc.getPageImageList(i):
xref = img[0]
pix = fitz.Pixmap(doc, xref)
if pix.n < 5: # this is GRAY or RGB
pix.writePNG("p%s-%s.png" % (i, xref))
else: # CMYK: convert to RGB first
pix1 = fitz.Pixmap(fitz.csRGB, pix)
pix1.writePNG("p%s-%s.png" % (i, xref))
pix1 = None
pix = None
I used this code to extract images from the pdf. I was sucessful for some pdfs but I was not able to do it for some pdfs. I was getting errors like
'NoneType' object has no attribute 'n'
DeviceCMYK not supported for png. Please let me know how to fix this and extract images from the pdf
Metadata
Metadata
Assignees
Labels
No labels