Created
December 14, 2018 10:05
-
-
Save MerleLiuKun/2d658e22a1677e04cff768b0c9229277 to your computer and use it in GitHub Desktop.
pdf file to image by page.
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 install PyMuPDF==1.14.3 | |
""" | |
import fitz | |
def convert_pdf_to_png(filename): | |
doc = fitz.open(filename=filename) | |
for pg in range(doc.pageCount): | |
page = doc[pg] | |
rotate = int(0) | |
zoom_x = 2.0 | |
zoom_y = 2.0 | |
trans = fitz.Matrix(zoom_x, zoom_y).preRotate(rotate) | |
pm = page.getPixmap(matrix=trans, alpha=False) | |
pm.writePNG('./{}.png'.format(pg + 1)) | |
if __name__ == '__main__': | |
f = '/path/to/name.pdf' | |
convert_pdf_to_png(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment