In this tutorial, we’re going to show you how to extract images from PDF in Python and convert them back to PDF.
We prepare this sample PDF that we will use for this tutorial.

Here’s what the output would look like.


How to Extract Images from PDF in Python
Follow these steps to extract images from a PDF file in Python:
- Install request module
- Add API Key
- Path to Source and Output File
- Setup Parameters
- Run Program
- Extract Image Demo
Step 1 – Install request module
- Have installed the request module already? If not, kindly install the requests module. You can do it by running this
python -m pip install requests
in your command line.
Step 2 – Add API Key
- Insert your API key into your Python code. You may get your API key here.
Step 3 – URL to Source and Path to Output File
- Add the URL to your source and path for your output file
Step 4 – Setup Parameters
- Set up the parameters for your PDF to PNG conversion
Step 5 – Run Program
- Once you’re done with your code, you may now run your program. You can see the output file in your folder
Step 6 – Extract Image Demo
- Here’s the program in action

How to Convert Them Back into PDF
Follow these steps to convert images back to PDF in Python.
Step 1 – URL to Source and Path to Output
- Add the URL to your source and path for your output file
Step 2 – Setup Parameters
- Set up the parameters for your PNG to PDF conversion
Step 3 – Run Program
- Once you’re done with your code, you may now run your program. You can see the output file in your folder
Step 4 – PNG to PDF Demo
- Here’s what the program in action looks like

You’ve learned how to convert PDF to PNG and convert the PNG back to PDF in Python with PDF Extractor API.