Best Practice to Python Convert PDF to Images for Beginners – Python Tutorial

By | August 1, 2019

To convert pdf to images, we can use ImageMagick + Wand library or ImageMagick + PythonMagick library, you also can use poppler + pdf2image. However, this python library depends on other application. In this tutorial, we will use a pure python library PyMuPDF to convert pdf files to images.

convert pdf to images

Install python library

pip install PyMuPDF

Import python library

import sys, fitz

Set pdf file path

pdf = 'e:\\lshort-cn.pdf'

Convert pdf to png page by page

doc = fitz.open(pdf)                        # open document
for page in doc:                            # iterate through the pages
    pix = page.getPixmap(alpha = False)     # render page to an image
    pix.writePNG("page-%i.png" % page.number)

Then you will find this pdf has converted images.

Leave a Reply