Created
August 23, 2019 19:10
-
-
Save shawngraham/e9fedb7c51b040eac00f8730cb9fef04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
pip instal fitz | |
pip install PyMuPDF | |
""" | |
import fitz | |
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment