PDF to Image

Convert PDF to Image in python

In this article, we are going to discuss the simplest approach to converting PDF to JPG online. We will also read about the conversion of PDF to Image using the cURL commands. No additional software download or installation is required and perform all the conversions within the cloud. Our Cloud API is so remarkable that it only requires input PDF and destination path and takes care of all internal conversion complexities.

PDF to JPG Conversion API

Apsose.PDF Cloud SDK for Python which is a wrapper around Aspose.PDF Cloud API enabling you to create, edit, manipulate PDF content and transform PDF files to various support formats. Now in order to use the SDK, the first step is its installation as its available for free download over PIP and GitHub. Please execute the following command on the terminal/command prompt to install the latest version of SDK on the system.

pip install asposepdfcloud

The next major step is a free subscription to our cloud services via Aspose.Cloud dashboard using GitHub or Google account. Or, simply create a new Account and obtain your Client Credentials details.

Convert PDF to JPG using Python

Please follow the steps given below to save PDF as JPG format and save the output in cloud storage.

  • Create an instance of ApiClient class while providing Client ID Client Secret as arguments
  • Now create an instance of PdfApi class that takes the ApiClient object as an input argument
  • The next step is to create variables holding the names of the input PDF file and resultant JPEG image
  • Finally, call the put_page_convert_to_jpeg(..) method of PdfApi taking the input PDF, page number to be converted, and name of the resultant JPEG file name.
pdf to image preview

Image 1:- PDF to JPG conversion preview.

The sample files used in the above example can be downloaded from URL2PDF.pdf and PDF2JPEG.jpeg.

Please note that in order to save the PDF to other raster image formats, please use the following methods

Use put_page_convert_to_tiff(…) to save PDF pages to TIFF
Use put_page_convert_to_png(…) to save PDF pages to PNG
Use put_page_convert_to_emf(..) to save PDF pages to EMF
Use put_page_convert_to_bmp(…) to save PDF pages to BMP
Use put_page_convert_to_gif(…) to save PDF pages to GIF

Convert PDF to JPG using cURL Commands

The cURL command can also be used to access REST APIs via command line terminals. So we are going to convert the first page of PDF to JPG where the resultant file is saved to Cloud storage. Now in order to access Aspose.PDF Cloud, we need to first generate a JSON Web Token (JWT) while executing the following command.

curl -v "https://api.aspose.cloud/connect/token" \
-d "grant_type=client_credentials&client_id=bbf94a2c-6d7e-4020-b4d2-b9809741374e&client_secret=1c9379bb7d701c26cc87e741a29987bb" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Now that we have the JWT token, please execute the following command to convert pdf to image format.

curl -v -X PUT "https://api.aspose.cloud/v3.0/pdf/URL2PDF.pdf/pages/1/convert/jpeg?outPath=ConvertedPage.jpeg&width=800&height=1000" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
pdf to image preview

Image 2:- PDF to image conversion preview.


This article has explained the steps and related details on how we can convert PDF to JPG format. We have also explored the conversion of PDF to Image through cURL commands. Apart from this, we recommend you to visit the Programmers guide to learn more about other exciting features offered by the API. Please note that the complete source code of Apsose.PDF Cloud SDK for Python is available for download under the MIT license over GitHub.

In case you encounter any issues while using the API or you have any further queries, please feel free to contact us via the free product support forum.

We also recommend visiting the following links to learn more about