Assemble & split
merge, split, extract-pages, remove-pages, rotate, reorder.
The page-level toolkit lives under /v1/pdf/*. Every operation takes PDFs as
base64 strings in a JSON body and — unless noted — returns the resulting
PDF binary directly.
# Encode a file once, reuse it in the requests below
PDF=$(base64 -w0 input.pdf) # macOS: base64 -i input.pdfMerge
POST /v1/pdf/merge — combine 2+ PDFs, in order:
curl -X POST https://api.pdf-forge.dev/v1/pdf/merge \
-H "Authorization: Bearer $PDFFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"pdfs\": [\"$(base64 -w0 a.pdf)\", \"$(base64 -w0 b.pdf)\"]}" \
--output merged.pdfimport { readFile, writeFile } from "node:fs/promises";
const a = new Uint8Array(await readFile("a.pdf"));
const b = new Uint8Array(await readFile("b.pdf"));
const merged = await client.merge([a, b]);
await writeFile("merged.pdf", merged.buffer);Split
POST /v1/pdf/split — one PDF per page. This one returns JSON:
curl -X POST https://api.pdf-forge.dev/v1/pdf/split \
-H "Authorization: Bearer $PDFFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"pdf\": \"$PDF\"}"{ "pages": ["<base64 page 1>", "<base64 page 2>"], "page_count": 2,
"message": "PDF split into 2 pages" }const result = await client.split(pdfBytes);
// result.pages: Uint8Array[], result.pageCount: numberExtract, remove, reorder
Page selections are arrays of strings: single pages ("3") and ranges
("5-8").
# Keep only these pages, in the given order
curl -X POST https://api.pdf-forge.dev/v1/pdf/extract-pages \
-H "Authorization: Bearer $PDFFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"pdf\": \"$PDF\", \"pages\": [\"1\", \"3\", \"5-8\"]}" \
--output extracted.pdf
# Delete these pages, keep the rest
curl -X POST https://api.pdf-forge.dev/v1/pdf/remove-pages \
-H "Authorization: Bearer $PDFFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"pdf\": \"$PDF\", \"pages\": [\"2\", \"4\"]}" \
--output trimmed.pdfReordering = extract-pages
extract-pages preserves the order you give. To reorder a 3-page document,
extract all pages in the new sequence: "pages": ["3", "1", "2"].
Rotate
POST /v1/pdf/rotate — rotation must be a non-zero multiple of 90
(negative for counter-clockwise). Optional pages limits the scope:
curl -X POST https://api.pdf-forge.dev/v1/pdf/rotate \
-H "Authorization: Bearer $PDFFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"pdf\": \"$PDF\", \"rotation\": 90, \"pages\": [\"1\"]}" \
--output rotated.pdfOne unit per operation
Each successful call meters one unit against your monthly quota, like a generation. Errors are not counted.
Next steps
- Compress — shrink the merged result.
- Secure — protect, watermark, number the pages.
- PDF & images — rasterize pages or build a PDF from scans.