How to convert PDF to image by Python

pdf2image is a Python wrapper for poppler.

In this article, I illustrate how to convert a PDF file to a image file by pdf2image.

 

The environment is as shown below.

windows10 64 bit

python 3.6 ( accompanying with Anaconda )

 

1) Installing poppler 

Download poppler-0.51_x86.7z from here. When you extract this file, a folder named poppler-0.51 appears on Desktop.

 

To connect path, execute the following command.

set path=%path%;C:\Users\user_name\Desktop\poppler-0.51\bin 

 

Then, to check the connection,  execute the following command.

 pdfinfo.exe

If information is returned properly, you successfully connect the path to poppler. 

 

2) Installing pdf2image

Download pdf2image-0.1.14.tar.gz from here. When you extract this file, a folder named pdf2image-0.1.14 appears on Desktop.

 

Move to the above folder, and set up by the following command.

python setup.py install

 

3) Convert PDF to image

prepare a pdf file (here, I name it "test.pdf"), and execute the following code in the directory where the pdf file is. 

from pdf2image import convert_from_path, convert_from_bytes

images = convert_from_path('test.pdf')
images[0].save('test.png', 'png')

 

Note:

I moved the folder, pdf2image-0.1.14, to ~/anaconda3/Lib/site-packages, because I do not know "setup.py" well. When you do not succeed to convert PDF, please try it.