Convert pdf to jpg in python

The pdf2image library can be used.

Step 1:

First you need poppler-utils

pdftoppm and pdftocairo are the piece of software that do the actual magic. It is distributed as part of a greater package called poppler.

Using pip

Windows users will have to install poppler for Windows, then add the bin/ folder to PATH.

Mac users will have to install poppler for Mac.

Linux users will have both tools pre-installed with Ubuntu 16.04+ and Archlinux. If it’s not, run 

sudo apt install poppler-utils

Using conda

conda install -c conda-forge poppler

Then you can install the pip package!

pip install pdf2image

Install Pillow if you don’t have it already with 

pip install pillow

 

Step 2:

Once installed you can use following code to get images.

from pdf2image import convert_from_pathpages = convert_from_path('pdf_file', 500)

 

Step 3

Saving pages in jpeg format

i = 0
for page in pages:

i += 1 page.save('out'+str(i)+'.jpg', 'JPEG')