Compress PDF API
Re-save with object streams, dropping unreferenced objects. Does not resample images.
| Endpoint | POST https://astralpdf.com/api/v1/compress-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
Size limits are where automated document flows fail: an email attachment cap, an upload form, a storage bill. Compressing at the end of the job means the limit is respected every time rather than discovered when a send fails.
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/compress-pdf \
-H "Authorization: Bearer ast_YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"input": "JVBERi0xLjcKJYGBgYEK..."}'response
{
"tool": "compress-pdf",
"result": "JVBERi0xLjcKJWDjz9MKMSAwIG9iago8PC9UeXBlL0NhdGFsb2c...",
"chars": 3120,
"ms": 67
}In your language
JavaScript
const res = await fetch("https://astralpdf.com/api/v1/compress-pdf", {
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/compress-pdf",
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
- How much smaller will my file get?
- It depends entirely on the file. A document carrying unreferenced objects and an uncompressed cross-reference table can lose a good deal; a lean one loses almost nothing.
- Does it resample images?
- No, and that is the honest limit: an image-heavy scan will barely move. Images are left at their original resolution rather than being quietly degraded.
- Is anything lost?
- Nothing visible. The structure is rewritten and objects nothing refers to are dropped. Pages, text and images come through unchanged.
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