How to Convert Images to PDF in Python
- Add Files in the Folder
- Install the Module Requests
- Add your PDF.co API Key
- Add Source Files
- Run the Python Program
- PDF.co Web API Demo
In this demonstration, we will convert Images to PDF in Python using the PDF.co Web API. We will use the Images to PDF Web API /v1/pdf/convert/from/image
endpoint. Below is a GIF of two sample images and the converted PDF output.

Step 1: Add Files in the Folder
First, add your sample file to the Python program folder. You can download our Python sample code here.
Step 2: Install the Module Requests
Next, if you haven’t yet, kindly install the requests module. Enter this line python -m pip install requests
in your command line.
Step 3: Add your PDF.co API Key
Let’s, open the Python sample code and proceed to line 6. Add your PDF.co API Key in this line. You can get your API Key in your PDF.co dashboard.
Step 4: Add Source Files
Let’s add the source files.
In line 12, add the image files you’d like to convert to PDF in an array.
In line 14, enter your desired output filename.
Step 5: Run the Python Program
You can now run the Python program and you’ll find the PDF output in your folder.
Step 6: PDF.co Web API Demo
Here are the Images of PDF Web API in action.

In this tutorial, you learned how to convert images to PDF in Python using the PDF.co Web API. The Web API supports JPEG, PNG, and TIFF image formats. You also learned which part of the source code to change to get you started right away.