How to Rasterize PDF Files with cURL

Learn how to use cURL to flatten each page of a PDF document to a rasterized image with pdfRest Rasterize PDF API tool.
Share this page

Why Rasterize PDF Files with cURL?

The pdfRest Rasterize PDF API Tool is a powerful utility that allows users to convert vector-based PDF files into rasterized images. This process can be beneficial for ensuring consistent rendering across different platforms and devices. In this tutorial, we will demonstrate how to send an API call to the Rasterize PDF endpoint using cURL, a command-line tool for transferring data with URLs.

A user might need to rasterize a PDF to ensure that the document's appearance remains consistent when viewed on various devices or platforms that may not support vector graphics. For example, a graphic designer might rasterize a PDF to ensure that complex designs or fonts display correctly when shared with clients who might use different software or devices.

Rasterize PDF with cURL Code Example

curl -X POST "https://api.pdfrest.com/rasterized-pdf" \
  -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"

Source: GitHub

Breaking Down the Code

The code provided is a cURL command that sends a POST request to the pdfRest API to rasterize a PDF file. Let's break down each part:

curl -X POST "https://api.pdfrest.com/rasterized-pdf"

This line specifies the use of cURL to make a POST request to the specified URL, which is the endpoint for the Rasterize PDF API.

-H "Accept: application/json"

This header indicates that the client expects a JSON response from the server, which is a common format for API responses.

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

This header specifies that the request body will be sent as multipart/form-data. This is necessary when uploading files to the server.

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

The API key is required for authentication. It should be replaced with your actual API key, which you can obtain from your pdfRest account.

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

This option specifies the file to be uploaded. Replace /path/to/file with the actual path to the PDF file you want to rasterize.

-F "output=example_out"

This option specifies the desired name for the output file. The rasterized PDF will be saved with this name.

Beyond the Tutorial

In this tutorial, we successfully demonstrated how to use cURL to send a POST request to the pdfRest Rasterize PDF API. This allows you to convert vector-based PDFs into rasterized images, ensuring consistent rendering across different platforms.

We encourage you to explore all of the pdfRest API Tools in the API Lab. For more detailed information about each API, 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 GitHub.

Generate a self-service API Key now!
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.