pdf.compress
Make a PDF smaller: subset fonts, compress and deduplicate streams, drop unused objects.
POST /v1/pdf/compress
| Input | one file, sent as multipart/form-data; the optional options part is a JSON object |
| Output | one PDF |
| Credits | 1 credit per 10 pages, rounded up to whole blocks of 10 pages, with a minimum of 1 credit |
| Limits | [size, page and time limits: no claim ID yet] |
| Reads or changes the document | returns a changed copy |
| Error statuses | 400, 413, 422, 500, 501, 504 (see Errors) |
Options
Section titled “Options”| Option | Type | Required | Default | Description |
|---|---|---|---|---|
password |
string | no | Password of an encrypted document. | |
preset |
string | no | Compression preset. Default strict. strict: Every lossless pass. The default. lossy: Every pass the strict preset has, plus lossy ones as the SDK adds them. archival: Only passes that keep every object a later incremental update could use. |
Example
Section titled “Example”curl -sS -f -X POST "$PDFLUENT_API_URL/v1/pdf/compress" \ -H "x-api-key: $PDFLUENT_API_KEY" \ -o result.pdfimport jsonimport os
import requests
parts = [ ("file", ("structured.pdf", open("structured.pdf", "rb"))),]
response = requests.post( os.environ["PDFLUENT_API_URL"] + "/v1/pdf/compress", headers={"x-api-key": os.environ["PDFLUENT_API_KEY"]}, files=parts,)response.raise_for_status()
with open("result.pdf", "wb") as out: out.write(response.content)import { openAsBlob } from 'node:fs';import { writeFile } from 'node:fs/promises';
const form = new FormData();form.append('file', await openAsBlob("structured.pdf"), "structured.pdf");
const response = await fetch(process.env.PDFLUENT_API_URL + "/v1/pdf/compress", { method: 'POST', headers: { 'x-api-key': process.env.PDFLUENT_API_KEY }, body: form,});if (!response.ok) throw new Error(`${response.status} ${await response.text()}`);
await writeFile("result.pdf", Buffer.from(await response.arrayBuffer()));The key goes in the x-api-key header; see Authentication. Every response carries x-pdfluent-pages and x-pdfluent-credits.