Learn how to programmatically merge, split, and compress PDFs using a REST API. Python, JavaScript, and cURL code examples included.
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:
Our PDF API supports 11 operations, all accessible via simple REST endpoints:
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 -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
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)
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
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
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
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}
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
11 PDF operations. Free tier: 100 requests/day, 10MB per file. No credit card.
Get Free API KeyGet your free API key and start making requests in minutes.
curl "http://147.224.212.116/api/..." \
-H "X-API-Key: YOUR_API_KEY"
Get a free API key with 100 requests/day. No credit card required.
Get Free API Key