Merging and Splitting PDFs Programmatically with an API

Manipulation

When You Need to Merge or Split PDFs

Common scenarios:

  • Merge — combine a cover letter, CV, and portfolio into one submission PDF
  • Merge — consolidate monthly reports into an annual archive
  • Split — extract a single chapter from a large manual
  • Split — separate multi-page scan batches into individual documents

Merging PDFs

curl -X POST https://api.toolkitapi.io/v1/pdf/merge \
  -H "X-API-Key: $API_KEY" \
  -F "files[][email protected]" \
  -F "files[][email protected]" \
  -F "files[][email protected]" \
  --output combined.pdf

Files are merged in the order supplied. The output preserves all metadata, bookmarks, and form fields from the source documents.

Splitting by Page Range

curl -X POST https://api.toolkitapi.io/v1/pdf/split \
  -H "X-API-Key: $API_KEY" \
  -F "[email protected]" \
  -F "pages=1-10" \
  --output chapter1.pdf

For multiple ranges, pass pages as a comma-separated list. The API returns a ZIP file containing one PDF per range.

Splitting into Individual Pages

Omit pages to split every page into a separate file:

{ "mode": "individual" }

Useful for creating thumbnail previews: split once, then convert each single-page PDF to an image.

Programmatic Merge Pipeline

import httpx

files = [open(f, "rb") for f in ["contract.pdf", "appendix_a.pdf", "appendix_b.pdf"]]
resp = httpx.post(
    "https://api.toolkitapi.io/v1/pdf/merge",
    headers={"X-API-Key": API_KEY},
    files=[("files[]", f) for f in files],
)
for f in files:
    f.close()

Path("output/full_contract.pdf").write_bytes(resp.content)

Try it out

Browse Tools →

More from the Blog