Convert pdf to image using python ( Flask )

Udit Rawat
DrupalJournal
Published in
2 min readMar 15, 2018

--

Previously I have written article about how to generate images from pdf using javascript ( pdf.js ). I was finding some better solution for this process and then I give a try to python.

In this article, we will see how to generate images from pdf using python. of course, we need some additional libraries of python to do this like flask, pillow, wand, and ImageMagick.

What is FLASK?

It’s a python micro-framework, it’s small but powerful and easy to learn a framework that enables us to build a web app in a short amount of time.

So let start with installing all the required libraries.

Install flask, pillow, and wand.

# flask command
pip install flash

# Install pillow
pip install pillow

# Install wand
pip install wand

Install & link ImageMagick.

# Steps to install ImageMagick
brew install imagemagick@6
brew unlink imagemagick
brew link imagemagick@6 --force

Now create a template under template directory of your project and name it index.html, we will code our pdf upload form here.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pdf To Image Service</title>
<link

--

--

Udit Rawat
DrupalJournal

Full Stack Developer, Passionate about innovations in coding and mobile applications. [https://drupaljournal.com/]