Learn how to extract and save images from PDF files in Python using PyMuPDF and Pillow libraries.

In this tutorial, we will write a Python code to extract images from PDF files and save them in the local disk using PyMuPDF and Pillow libraries.

With PyMuPDF, you are able to access PDF, XPS, OpenXPS, epub and many other extensions. It should run on all platforms including Windows, Mac OSX and Linux.

Let’s install it along with Pillow:

pip3 install PyMuPDF Pillow

Copy

Open up a new Python file and let’s get started. First, let’s import the libraries:

import fitz ## PyMuPDF
import io
from PIL import Image

Copy

I’m gonna test this with this PDF file, but you’re free to bring and PDF file and put it in your current working directory, let’s load it to the library:

## file path you want to extract images from
file = "1710.05006.pdf"
## open the file
pdf_file = fitz.open(file)

#python #images #web-development

How to Extract Images from PDF in Python using PyMuPDF and Pillow
59.45 GEEK