How to Delete Pages from PDF Files with cURL

Learn how to remove unwanted PDF pages with cURL by defining the page ranges that should remain in the output document.
Share this page

In the following tutorial, you'll use cURL and the Split PDF API Tool to delete pages from PDF files. The example keeps authentication, regional routing, file transfer, and operation settings explicit so the request used to delete pages from PDF files is easy to inspect and reuse.

Why Delete Pages from PDF Files with cURL?

Scanned packets and assembled reports sometimes contain blank sheets, separator pages, or superseded content that should not appear in the final PDF. Removing those pages programmatically avoids a manual editing step.

Suppose a six-page intake packet includes an unnecessary fourth page. The sample retains pages 1 through 3 and pages 5 through 6, producing a new PDF that omits page 4 while preserving the order of everything else.

Split PDF describes pages to keep, not pages to destroy. Applications working with variable-length documents should calculate the retained ranges from the current page count rather than copying the sample ranges unchanged.

cURL Code Example

# By default, we use the US-based API service. This is the primary endpoint for global use.
API_URL="https://api.pdfrest.com"

# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below.
# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
# API_URL="https://eu-api.pdfrest.com"

curl -X POST "$API_URL/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" \
  -F "pages[]=1-3,5,6"

Source for Delete Pages from PDF: View the cURL sample on GitHub.

Breaking Down the Code

Choose the pdfRest service region

# By default, we use the US-based API service. This is the primary endpoint for global use.
API_URL="https://api.pdfrest.com"

# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below.
# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
# API_URL="https://eu-api.pdfrest.com"

The Delete Pages from PDF example routes to the US service through the active URL, while the commented hostname provides the EU option. Keep every Delete Pages from PDF input and generated resource ID in the same region.

Build the authenticated multipart request

curl -X POST "$API_URL/split-pdf" \
  -H "Accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \

This POST targets the endpoint used by Delete Pages from PDF. For the Delete Pages from PDF request, Accept asks for JSON, Content-Type identifies the multipart payload, and Api-Key authenticates the call.

Upload the input file data

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

The Delete Pages from PDF request reads the local source from the path after @ and sends its bytes in the multipart file field. For Delete Pages from PDF, cURL treats the path as an upload rather than ordinary form text.

Set the operation-specific fields

-F "output=example_out" \
  -F "pages[]=1-3,5,6"

The repeated-array field syntax pages[] carries the retained range expression. In this example, 1-3,5,6 excludes page 4.

Read the generated resource response

curl -X POST "$API_URL/split-pdf" \

A successful Delete Pages from PDF call returns JSON describing the generated resource, including its output ID and download information. Preserve the Delete Pages from PDF result needed by the next workflow step before the configured retention period expires.

Beyond the Tutorial

This tutorial gives you a cURL pattern for producing a cleaned PDF while leaving the uploaded source unchanged.

Keep the original until you verify the retained-page result, especially when page ranges come from user input or another service. Validate that every range is within the document and that no required page was omitted.

Continue exploring the Delete Pages from PDF workflow in API Lab. For the complete Delete Pages from PDF request contract, accepted values, defaults, and limitations, consult the Split PDF API Tool documentation.

Note: The Delete Pages from PDF example above uploads a file with multipart form data. For source content already stored in pdfRest, the Delete Pages from PDF JSON payload example shows the resource-ID request shape.

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