There is an easy-to-use wonderful library called pdf2image which converts PDF files into JPEG or PNG images as requested. It works quite fine, but it generates multiple files for multi-page PDF files and I needed a single image containing all files in a PDF file, merged vertically, so pdf2image does not satisfy all my needs.

Then I found pillow to manipulate/process image files, from there I can merge multiple image files together. Here it goes:

Requirements

Installation requires two python modules and some extra libraries to process PDF files.

To install pillow:

pip install pillow

To install pdf2image:

pip install pdf2image

pdf2image requires poppler , the repo itself has the installation instructions. Since I’m a macOS user, I simply ran:

brew install poppler

Everything is ready.

The code

Below code piece is written with Python 3.7 . It first converts pdf to multiple images and then merges them together. Run it with the source pdf file path and the output folder path you want JPEG to be exported.