Split PDF API
Keep only the pages you name. Put the range in "option", for example 1-3,7.
| Endpoint | POST https://astralpdf.com/api/v1/split-pdf |
| Auth | Bearer token, free |
| Sends | input: base64 |
| Returns | result: base64 |
| Price | Free. 1,000 calls a day, 60 a minute. |
When to call it
Splitting is how a document becomes the part somebody actually needs: one invoice out of a batch print, a single chapter, the signature page. In a pipeline the ranges come from data rather than from a person clicking, which is the only way it scales past a handful of files.
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/split-pdf \
-H "Authorization: Bearer ast_YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"input": "JVBERi0xLjcKJYGBgYEK...", "option": "2-4,9"}'response
{
"tool": "split-pdf",
"result": "JVBERi0xLjcKJWDjz9MKMSAwIG9iago8PC9UeXBlL0NhdGFsb2c...",
"chars": 2180,
"ms": 42
}In your language
JavaScript
const res = await fetch("https://astralpdf.com/api/v1/split-pdf", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"input": "JVBERi0xLjcKJYGBgYEK...", "option": "2-4,9"}),
});
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/split-pdf",
headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
json={"input": "JVBERi0xLjcKJYGBgYEK...", "option": "2-4,9"},
timeout=30,
)
res.raise_for_status()
result = res.json()["result"]Parameters
| Field | Type | Notes |
|---|---|---|
| input | string | Required. The file, base64 encoded. A data: URL is accepted too. Up to 6,000,000 characters per call. |
| option | string | See the example above. |
Errors
Errors are RFC 7807 problem documents with a stable type you can branch on.
| missing-token | 401 | No Authorization header. |
| bad-request | 400 | input missing or the wrong type. |
| tool-failed | 422 | The input could not be processed. detail says why. |
| quota-exceeded | 429 | Past 1,000 calls today. |
Questions
- How do I write the range?
- In "option", one-based, the way a reader numbers pages: "1-3" for the first three, "2,5" for two pages, "1-3,7,9-10" for a mix.
- Does the order I ask for matter?
- Yes. "3,1" returns page three followed by page one. The pages come back in the order requested rather than sorted.
- What if I ask for a page that does not exist?
- You get a 422 naming the real page count and the page you asked for, rather than a shorter file than you expected.
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