Convert Images to PDF in Python using PDF.co Web API
In this tutorial, 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.
Step 1: Download Sample Code
Please download the Python Sample Code for this tutorial!
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 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!
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.