How to Convert PDF to JPG with cURL

Learn how to convert PDF pages into JPG images with pdfRest PDF to Images API Tool using cURL
Share this page

Why Convert PDF to JPG with cURL?

The pdfRest PDF to Images API Tool is a powerful resource for developers who need to convert PDF documents into image files programmatically. This tool provides a simple and efficient way to transform entire PDFs or select pages into images in various formats such as JPEG, PNG, and TIFF. This tutorial will guide you through the process of sending an API call to the PDF to Images API using cURL, a command-line tool for getting or sending data using URL syntax.

There are many scenarios where converting a PDF to images could be useful. For instance, a web application might allow users to preview the first page of a PDF document as a thumbnail before downloading it. Alternatively, a document management system might convert uploaded PDFs into images to enable quick viewing without the need for a PDF reader. These are just a couple of examples where the PDF to Images API can be utilized.

PDF to JPG with cURL Code Example

curl -X POST "" \
  -H "Accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
  -F "file=@/path/to/file" \
  -F "output=example_out" \
  -F "pages=1-last" \
  -F "resolution=300" \
  -F "color_model=rgb" \
  -F "jpeg_quality=100"

Reference to the code: pdfRest API samples on GitHub.

Breaking Down the Code

The above code block demonstrates how to use cURL to make a POST request to the pdfRest API's PDF to Images endpoint. Here's what each part of the command does:

-X POST ""

This specifies that you are making a POST request to the endpoint that converts PDFs to JPG images.

-H "Accept: application/json"

This header tells the server that the client expects a response in JSON format.

-H "Content-Type: multipart/form-data"

This header indicates that the data being sent in the request is multipart form data, which is necessary for file uploads.

-H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

You must replace the placeholder with your actual API key to authenticate the request.

-F "file=@/path/to/file"

This form field is where you specify the file path to the PDF you want to convert.

-F "output=example_out"

Here you define the base name for the output files. The API will add a page number and file extension to this base name.

-F "pages=1-last"

This field specifies the range of pages to convert. "1-last" means all pages in the PDF will be converted.

-F "resolution=300"

The resolution field sets the DPI (dots per inch) for the output images, which affects their quality and size.

-F "color_model=rgb"

This option sets the color model for the output images. "rgb" is suitable for full-color images.

-F "jpeg_quality=100"

Finally, this sets the quality of the JPEG output. A value of 100 indicates the highest quality.

Beyond the Tutorial

In this tutorial, you've learned how to use cURL to call the pdfRest PDF to Images API to convert a PDF into high-quality images. By following the steps outlined above, you can integrate this functionality into your own applications or workflows. To explore more possibilities and try out all of the pdfRest API Tools, visit the API Lab. For a deeper understanding of the API's capabilities and additional options you can use in your requests, refer to the API Reference Guide.

Note: This is an example of a multipart API call. Code samples using JSON payloads can be found at pdfRest API samples on GitHub.

Generate a self-service API Key now!

Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.

Compare Plans
Contact Us