Skip to main content

Compress PDF API

Re-save with object streams, dropping unreferenced objects. Does not resample images.

EndpointPOST https://astralpdf.com/api/v1/compress-pdf
AuthBearer token, free
Sendsinput: base64
Returnsresult: base64
PriceFree. 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

FieldTypeNotes
inputstringRequired. 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-token401No Authorization header.
bad-request400input missing or the wrong type.
tool-failed422The input could not be processed. detail says why.
quota-exceeded429Past 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