PDF metadata API
Page count, page sizes, rotation and document metadata.
| Endpoint | POST https://astralpdf.com/api/v1/pdf-info |
| Auth | Bearer token, free |
| Sends | input: base64 |
| Returns | result: json |
| Price | Free. 1,000 calls a day, 60 a minute. |
When to call it
Most PDF work starts with a question about the file: how many pages, what size, is it landscape, who produced it. Answering that in a validation step is what stops a 400-page upload, a mixed-orientation batch or an empty file reaching the process that assumed none of those.
Example
curl
curl -X POST https://astralpdf.com/api/v1/pdf-info \
-H "Authorization: Bearer ast_YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"input": "JVBERi0xLjcKJYGBgYEK..."}'response
{
"tool": "pdf-info",
"result": "{\n \"pages\": 12,\n \"title\": \"Quarterly report\",\n \"author\": null,\n \"producer\": \"pdf-lib\",\n \"bytes\": 48213,\n \"pageSizes\": [{ \"page\": 1, \"width\": 595, \"height\": 842, \"rotation\": 0 }]\n}",
"chars": 214,
"ms": 11
}In your language
JavaScript
const res = await fetch("https://astralpdf.com/api/v1/pdf-info", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"input": "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/pdf-info",
headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
json={"input": "JVBERi0xLjcKJYGBgYEK..."},
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. |
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
- What units are the page sizes in?
- PDF points, where 72 points is an inch. An A4 page reads 595 by 842 and US Letter reads 612 by 792.
- Does it work on an encrypted PDF?
- No. An encrypted file has to be opened first: call unlock-pdf with its password, then read the result.
- Is the whole file uploaded?
- Yes, base64 in the request body. It is processed in memory and not written to disk, and only the call itself is recorded.
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