Skip to main content

Merge PDF API

Join several PDFs into one, in the order given.

EndpointPOST https://astralpdf.com/api/v1/merge-pdf
AuthBearer token, free
Sendsinputs: base64[]
Returnsresult: base64
PriceFree. 1,000 calls a day, 60 a minute.

When to call it

Merging is nearly always the last step of something automated: invoices for a month, a report and its appendices, a signed contract and its attachments. Doing it in the job that produced the parts is what keeps the order right and stops anyone assembling it by hand at the end of the month.

For a one-off, the browser version needs no token and never sends your data anywhere: it runs on your own machine.

Example

curl
curl -X POST https://astralpdf.com/api/v1/merge-pdf \
  -H "Authorization: Bearer ast_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"inputs": ["JVBERi0xLjcKJYGBgYEK...","JVBERi0xLjcKJYGBgYEK..."]}'
response
{
  "tool": "merge-pdf",
  "result": "JVBERi0xLjcKJWDjz9MKMSAwIG9iago8PC9UeXBlL0NhdGFsb2c...",
  "chars": 4212,
  "ms": 85
}

In your language

JavaScript
const res = await fetch("https://astralpdf.com/api/v1/merge-pdf", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"inputs": ["JVBERi0xLjcKJYGBgYEK...","JVBERi0xLjcKJYGBgYEK..."]}),
});
if (!res.ok) throw new Error((await res.json()).detail);
const { result } = await res.json();
Python
import os, requests

res = requests.post(
    "https://astralpdf.com/api/v1/merge-pdf",
    headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
    json={"inputs": ["JVBERi0xLjcKJYGBgYEK...","JVBERi0xLjcKJYGBgYEK..."]},
    timeout=30,
)
res.raise_for_status()
result = res.json()["result"]

Parameters

FieldTypeNotes
inputsstring[]Required. The file, base64 encoded. A data: URL is accepted too. Between 2 and 20 items. Up to 6,000,000 characters per call.

Errors

Errors are RFC 7807 problem documents with a stable type you can branch on.

missing-token401No Authorization header.
bad-request400inputs missing or the wrong type.
tool-failed422The input could not be processed. detail says why.
quota-exceeded429Past 1,000 calls today.

Questions

How many files can I merge in one call?
Up to twenty, and their base64 counts together against the size limit for the call. For more, merge in batches and then merge the results.
Is the order guaranteed?
Yes. Pages appear in the order the documents appear in the inputs array, with no sorting of any kind.
What comes back?
The result is the new PDF, base64 encoded. Decode it and write it to a file.

Other endpoints

A token takes thirty seconds

Free, no card, 1,000 calls a day, and the same token works on astraltext.com, astralpdf.com, astraljson.com and astralbatch.com.

Get a free token