How to Extract Pages from PDF Files with cURL

Learn how to use pdfRest Split PDF API Tool to extract pages from PDF files with cURL
Share this page

Why Extract PDF Pages with cURL?

The pdfRest Split PDF API Tool is a powerful resource for developers who need to programmatically extract PDF pages into separate documents. This tool can be accessed via an API, allowing for automation and integration into various workflows. This tutorial will show how to send an API call to Split PDF with cURL, a command-line tool used for transferring data with URLs. cURL is a popular choice for interacting with APIs due to its flexibility and wide support across different platforms.

A user might need to extract PDF pages when dealing with large documents that need to be distributed in smaller sections. For instance, a user might have a PDF containing multiple invoices or reports that they want to separate into individual files for each client or department. Using the Split PDF API, this can be done programmatically, saving time and reducing the potential for human error that comes with manual page extraction

Extract PDF Pages with cURL Code Example

curl -X POST "https://api.pdfrest.com/split-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 of the provided code: pdf-rest-api-samples on GitHub.

Breaking Down the Code

The above cURL command is used to split a PDF document by making a POST request to the pdfRest API. Let's break down each part of the command:

-X POST

This specifies the request method, which in this case is POST, indicating that you are creating or updating resources on the server.

"https://api.pdfrest.com/split-pdf"

This is the endpoint URL to which the request is sent. It is specific to the Split PDF functionality of the pdfRest API.

-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 request body contains form data, allowing you to send files as part of the request.

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

This header includes your API key, which is required for authentication with the pdfRest API. Replace the placeholder with your actual API key.

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

The '-F' flag is used to specify each field to be sent as part of the multipart/form-data. In this case, it specifies the file to be uploaded. The '@' symbol is followed by the file path of the PDF you want to split.

-F "output=example_out"

This is another field in the form data. It specifies the prefix for the output files that will be generated after the split operation.

Beyond the Tutorial

By following the steps outlined in this tutorial, you have learned how to make a multipart API call to split a PDF document using cURL. This is just one of the many features offered by the pdfRest API. To explore and demo all of the pdfRest API Tools, visit the API Lab. For a comprehensive guide on how to use the API, refer to the API Reference Guide.

Note: This is an example of a multipart API call. Code samples using JSON payloads for the Split PDF API can be found at pdf-rest-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