HomeGuides › How to Merge PDF Files with One API Call

How to Merge PDF Files with One API Call

Merging PDFs server-side usually means installing and maintaining native libraries. A REST call removes the dependency.

Provide file URLs or base64 content; the service returns the merged PDF as a base64 string plus the page count.

The endpoint

POST /merge takes a JSON body with a "files" array of two or more inputs. Each entry is either {"base64": "..."} or {"url": "https://..."}, in any combination. Array order defines page order.

Quick start

curl
curl -X POST "https://pdf-toolkit2.p.rapidapi.com/merge" \
  -H "X-RapidAPI-Key: YOUR_KEY" \
  -H "X-RapidAPI-Host: pdf-toolkit2.p.rapidapi.com" \
  -H "Content-Type: application/json" \
  -d '{"files":[{"url":"https://example.com/a.pdf"},{"url":"https://example.com/b.pdf"}]}'

Saving the result

The response is {"pdfBase64": "...", "pageCount": n}. Decode pdfBase64 to bytes to get the merged file.

Node.js — save the merged file
const res = await fetch("https://pdf-toolkit2.p.rapidapi.com/merge", {
  method: "POST",
  headers: {
    "X-RapidAPI-Key": "YOUR_KEY",
    "X-RapidAPI-Host": "pdf-toolkit2.p.rapidapi.com",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ files: [{ url: "https://example.com/a.pdf" }, { url: "https://example.com/b.pdf" }] }),
});
const { pdfBase64, pageCount } = await res.json();
require("fs").writeFileSync("merged.pdf", Buffer.from(pdfBase64, "base64"));
console.log("pages:", pageCount);

The rest of the toolkit

/split extracts pages or page ranges into a new document. /info returns page count, dimensions, and metadata. /watermark stamps diagonal text across every page. /rotate turns pages 90, 180, or 270 degrees.

Run it in production

PDF Toolkit has a permanent free tier — 1,000 requests a month, no credit card. Paid plans start at $5/month for 100,000 requests.

Get a free API key on RapidAPI ↗

Full endpoint reference →

FAQ

Are there file size limits?

Yes, inputs are capped to keep responses fast. Very large PDFs should be split into parts first.

Are my files stored?

No. Processing happens in memory and the documents are discarded as soon as the response is sent.

Can I mix base64 and URL inputs?

Yes. Any combination of the two input formats is accepted in one request.