PDF API - How to Merge, Split & Compress PDFs with a REST API

Published Feb 20, 2026 · Tutorial · 5 min read

Learn how to programmatically merge, split, and compress PDFs using a REST API. Python, JavaScript, and cURL code examples included.

Why Automate PDF Processing?

PDFs are the universal document format, but manipulating them programmatically is surprisingly complex. Libraries like PyPDF2, pdf-lib, or Apache PDFBox require significant setup and have inconsistent APIs. A PDF REST API handles the heavy lifting — send files in, get processed files back.

Common automation scenarios:

PDF Toolkit API Features

Our PDF API supports 11 operations, all accessible via simple REST endpoints:

Merge PDFs
Split by Pages
Compress
Rotate Pages
Add Watermark
Extract Text
Read Metadata
Password Protect
Unlock PDF
Images to PDF
Page Numbers

Merge Multiple PDFs

Combine two or more PDF files into a single document. The order of files in the request determines the page order in the output.

cURL

curl -X POST "https://api.commandsector.in/api/pdf/merge?api_key=YOUR_KEY" \
  -F "files=@invoice1.pdf" \
  -F "files=@invoice2.pdf" \
  -F "files=@invoice3.pdf" \
  --output merged.pdf

Python

import requests

files = [
    ("files", open("invoice1.pdf", "rb")),
    ("files", open("invoice2.pdf", "rb")),
    ("files", open("invoice3.pdf", "rb")),
]
response = requests.post(
    "https://api.commandsector.in/api/pdf/merge",
    params={"api_key": "YOUR_KEY"},
    files=files
)
with open("merged.pdf", "wb") as f:
    f.write(response.content)

Split PDFs

Extract specific pages from a PDF. Specify page ranges like "1-3,5,7-10" to create a new PDF with only those pages.

# Extract pages 1-3 and 5
curl -X POST "https://api.commandsector.in/api/pdf/split?api_key=YOUR_KEY" \
  -F "file=@document.pdf" \
  -F "pages=1-3,5" \
  --output extract.pdf

Compress PDFs

Reduce PDF file size by optimizing images and removing unnecessary data. Typical compression: 40-60% size reduction without noticeable quality loss.

curl -X POST "https://api.commandsector.in/api/pdf/compress?api_key=YOUR_KEY" \
  -F "file=@large-report.pdf" \
  --output compressed.pdf

# Check the size difference
ls -lh large-report.pdf compressed.pdf

More Operations

Add Watermark

curl -X POST "https://api.commandsector.in/api/pdf/watermark?api_key=YOUR_KEY" \
  -F "file=@contract.pdf" \
  -F "text=CONFIDENTIAL" \
  -F "opacity=0.3" \
  --output watermarked.pdf

Extract Text

curl -X POST "https://api.commandsector.in/api/pdf/extract-text?api_key=YOUR_KEY" \
  -F "file=@document.pdf"
# Returns: {"text": "Full text content of the PDF...", "pages": 5}

Password Protect

curl -X POST "https://api.commandsector.in/api/pdf/protect?api_key=YOUR_KEY" \
  -F "file=@sensitive.pdf" \
  -F "password=my-secure-pass" \
  --output protected.pdf

Start Processing PDFs

11 PDF operations. Free tier: 100 requests/day, 10MB per file. No credit card.

Get Free API Key

Quick Start

Get your free API key and start making requests in minutes.

curl "http://147.224.212.116/api/..." \
  -H "X-API-Key: YOUR_API_KEY"

Start Using This API Today

Get a free API key with 100 requests/day. No credit card required.

Get Free API Key