There is a library named pdf2image. You can install it with pip install pdf2image. Then, you can use the following to convert pages of the pdf to images of the required format:

from pdf2image import convert_from_path

pages = convert_from_path("pdf_file_to_convert")
for page in pages:
    page.save("page_image.jpg", "jpg")

Now you can use this image to apply opencv functions.

You can use BytesIO to do your work without saving the file:

from io import BytesIO
from PIL import Image

with BytesIO() as f:
   page.save(f, format="jpg")
   f.seek(0)
   img_page = Image.open(f)
Answer from dewDevil on Stack Overflow
🌐
42mate
blog.42mate.com › opencv-tesseract-is-a-powerful-combination
OpenCV + Tesseract is a powerful combination - Blog - 42mate
August 20, 2020 - To this end, we can use the pdf2image library. import numpy as np import pdf2image import cv2 #OpenCV library for python def convert_pdf_to_image(document, dpi): images = [] images.extend( list( map( lambda image: cv2.cvtColor( np.asarray(image), ...
Discussions

image - Python - Extract a PDF page as a jpeg - Stack Overflow
How can I efficiently save a particular page of a PDF as a jpeg file using Python? I have a Python Flask web server where PDFs will be uploaded and I want to also store jpeg files that correspond t... More on stackoverflow.com
🌐 stackoverflow.com
[python] Is there an efficient way to convert pdf to an image (.jpg/png) file without using any third party software ?
Hello! Thanks for submitting to r/developersIndia . This is a reminder that We also have a Discord server where you can share your projects, ask for help or just have a nice chat, level up and unlock server perks! Our Discord Server I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/developersIndia
7
9
June 27, 2021
Way to convert PDF to jpg
Well you have to use external libraries for this sort of thing unless you can find an API that will do the conversion for you. More on reddit.com
🌐 r/learnpython
15
2
April 27, 2021
Difficulty converting image from RGB to YCbCr
Image are display in RGB format, imshow treat the 3-way array of img2 as RGB planes. That is for whatever color space you used for manipulating the image, you need to convert back to RGB to show it. More on reddit.com
🌐 r/Python
5
0
September 12, 2014
People also ask

How can I convert a PDF to images using IronPDF in Python?
To convert a PDF to images in Python with IronPDF, use the 'RasterizeToImageFiles' method. You first load a PDF with 'PdfDocument.FromFile', then call the 'RasterizeToImageFiles' specifying the output format and resolution.
🌐
ironpdf.com
ironpdf.com › how-tos › pdf to image
Python PDF to Image Conversion | IronPDF
Why is PDF-to-image conversion useful for developers?
PDF-to-image conversion is useful for creating document thumbnails, web previews, and integrating with image processing pipelines or machine learning models that require image input.
🌐
ironpdf.com
ironpdf.com › how-tos › pdf to image
Python PDF to Image Conversion | IronPDF
Can IronPDF handle converting embedded images within PDFs to separate image files?
Yes, IronPDF provides separate extraction methods to work with images already embedded in PDFs, which can be useful for specific workflows focusing on image content.
🌐
ironpdf.com
ironpdf.com › how-tos › pdf to image
Python PDF to Image Conversion | IronPDF
🌐
Medium
medium.com › @ravibs.mail › simple-extraction-of-contours-from-multi-page-pdf-files-python-cfa485776000
Simple extraction of contours from multi-page PDF files - Python | by Ravi Senanayake | Medium
July 26, 2020 - Below code snippet will read the PDF file sequence in a folder one by one and convert every page to image format, correct the orientation and save to a destination folder. #python 3.7 import os import tempfile from pdf2image import convert_from_path from PIL import Image import cv2def convert_pdf(file_path, output_path): # saves temporary image files in temorary directory and will be deleted upon completion with tempfile.TemporaryDirectory() as temp_dir: # convert pdf to multiple images images = convert_from_path(file_path, output_folder=temp_dir) # rotate image to correct orientation and save
🌐
PyPI
pypi.org › project › pdf2image
pdf2image · PyPI
A wrapper around the pdftoppm and pdftocairo command line tools to convert PDF to a PIL Image list.
🌐
IronPDF
ironpdf.com › how-tos › pdf to image
Python PDF to Image Conversion | IronPDF
August 2, 2026 - Batch processing: Loop over a directory of PDFs and convert each one in sequence, or use Python's concurrent.futures module for parallel processing · Selective extraction: Use the page index parameter to extract only the pages relevant to the use case · Image pipeline integration: Feed the output files into PIL/Pillow or OpenCV ...
🌐
Cloudinary
cloudinary.com › home › how to convert pdf to jpg with python
How to convert PDF to JPG with Python | Cloudinary
April 26, 2026 - pdf2image is a Python module that wraps pdftoppm and pdftocairo to convert PDF files to a PIL (Python Imaging Library) image object.
Find elsewhere
🌐
OpenGenus
iq.opengenus.org › pdf_to_image_in_python
A Pythonic Way of PDF to Image Conversion
January 15, 2019 - This library forms the core for utilities like Pdf2Image, PdfToText, and PDFToHTML which deals with PDFs. Refer Installation-2 for installing Poppler. 3. Pdf2image This is the python library which calls the pdftoppm library to convert a pdf to a sequence of PIL image objects.
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-pdf-to-image-using-python
Convert PDF to Image using Python - GeeksforGeeks
February 23, 2026 - Use convert_from_path() to read the PDF. Save each page as an image using save().
🌐
Better Programming
betterprogramming.pub › efficiently-convert-pdf-to-png-or-jpeg-images-in-python-50c5ce224c20
Efficiently Convert PDF to PNG or JPEG Images in Python | by Hatim Zahid | Better Programming
July 9, 2022 - Up till now, we don’t get the actual .png format image. from pdf2image import convert_from_bytespages = convert_from_bytes(file.read()) 4. Create a in memory buffer object and save the file as .png in in-memory buffer. We need to define an in-memory buffer that can store bytes. This is just like a python variable that stores data but here the data type is in ‘bytes’. You cannot store it normally by just defining a variable.
🌐
Docsaid
docsaid.org › en › blog › convert-pdf-to-images
Convert PDF to Images with Python | DOCSAID
February 14, 2024 - pdf2image provides rich optional ... suitable for cases where high-quality images are required: images = convert_from_path('/path/to/your/pdf/file.pdf', dpi=300)...
🌐
PyPI
pypi.org › project › img2pdf
img2pdf · PyPI
If the input is a JPEG, then it simply embeds the JPEG into the PDF in the same way as img2pdf does it. But for other image formats it uses flate compression of the plain pixel data and thus needlessly increases the output file size: $ convert logo: -resize 8000x original.png $ cat << END > pdflatex.tex \documentclass{article} \usepackage{graphicx} \begin{document} \includegraphics{original.png} \end{document} END $ pdflatex pdflatex.tex $ stat --format="%s %n" original.png pdflatex.pdf 4500182 original.png 9318120 pdflatex.pdf
🌐
GitConnected
levelup.gitconnected.com › 4-python-libraries-to-convert-pdf-to-images-7a09eba83a09
5 Python libraries to convert PDF to Images (Code Example) | by Prithivee Ramalingam | Level Up Coding
July 24, 2023 - It also enables you to create images directly from URLs and HTML sources. You can find the documentation of PDF to Image conversion on the IronPDF website. Pdf2image is a python module that wraps pdftoppm and pdftocairo to convert PDF to a PIL Image object. pdf2image supports 2 methods to convert pdf to images.
🌐
Quora
quora.com › How-can-I-convert-a-PDF-to-JPEG-using-Python-3
How to convert a PDF to JPEG using Python 3 - Quora
August 5, 2016 - Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
Pythonforundergradengineers
pythonforundergradengineers.com › pdf-to-multiple-images.html
Convert a PDF to Multiple Images with Python - Python for Undergraduate Engineers
October 18, 2019 - My PDF had three pages, so three .png image files were created. In this post, we used a Python package called pdf2image to convert a PDF file into a directory full of images.
Top answer
1 of 3
246

The pdf2image library can be used.

You can install it simply using,

pip install pdf2image

Once installed you can use following code to get images.

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

Saving pages in jpeg format

for count, page in enumerate(pages):
    page.save(f'out{count}.jpg', 'JPEG')

Edit: the Github repo pdf2image also mentions that it uses pdftoppm and that it requires other installations:

pdftoppm is the piece of software that does the actual magic. It is distributed as part of a greater package called poppler. Windows users will have to install [poppler for Windows] see ** below Mac users will have to install poppler for Mac. Linux users will have pdftoppm pre-installed with the distro (Tested on Ubuntu and Archlinux) if it's not, run sudo apt install poppler-utils.

You can install the latest version under Windows using anaconda by doing:

conda install -c conda-forge poppler

** note: Windows 64 bit versions upto 24.08 are available at https://github.com/oschwartz10612/poppler-windows but note that for 32 bit 22.02 was the last one included in TeXLive 2022 (https://poppler.freedesktop.org/releases.html) so you'll not be getting the latest features or bug fixes.

2 of 3
165

I found this simple solution, PyMuPDF, output to png file. Note the library is imported as "fitz", a historical name for the rendering engine it uses.

import fitz

pdffile = "infile.pdf"
doc = fitz.open(pdffile)
page = doc.load_page(0)  # number of page
pix = page.get_pixmap()
output = "outfile.png"
pix.save(output)
doc.close()

Note: The library changed from using "camelCase" to "snake_cased". If you run into an error that a function does not exist, have a look under deprecated names. The functions in the example above have been updated accordingly.

The fitz.Document class supports a context manager initialization:

with fitz.open(pdffile) as doc:
   ...
🌐
Wondershare
pdf.wondershare.com › jpg › pdf-to-jpg-python.html
Method to Convert PDF to JPG Using Python
February 9, 2022 - This post shows you the specific steps to convert PDF to JPG in Python with pdf2image and also a useful PDF to JPG converter without python,
🌐
Roy Tutorials
roytuts.com › home › python › convert pdf to image using python
Convert Pdf to Image using Python - Roy Tutorials
September 24, 2025 - When you have multiple pages with images in pdf file then you can save them one by one by appending some counter value to avoid overwriting the same output file. ... images = convert_from_path('output1.pdf') i = 1 for image in images: image.save('output' + str(i) + '.jpg', 'JPEG') i = i + 1