endpoint
Compress
POST /api/v1/compress
Reduce file size with lossy image re-encoding and lossless stream compression.
credits: 2returns: application/pdf
Image re-encoding is CPU-bound.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| file | multipart file | required | Source PDF. |
| level | "low" | "medium" | "high" | "max" | optional | Compression aggressiveness.default: medium |
| grayscale | boolean | optional | Flatten color to grayscale — big savings on scans. |
| stripMetadata | boolean | optional | Clear info dict and embedded XMP. |
| imageMaxDpi | integer | optional | Downsample images above this DPI.default: 150 |
Examples
curl
curl -X POST https://api.snappdf.au/api/v1/compress \
-H "Authorization: Bearer $SNAPPDF_API_KEY" \
-F "file=@big.pdf" -F "level=max" -F "grayscale=true" \
-o small.pdfJavaScript
const r = await snap.pdf.compress({ file: bytes, level: 'max', grayscale: true });
console.log(r.originalSize, '→', r.compressedSize);Python
r = snap.pdf.compress(file=bytes, level="max", grayscale=True)PHP
$r = $snap->pdf->compress(file: $bytes, level: 'max', grayscale: true);Ruby
r = snap.pdf.compress(file: bytes, level: 'max', grayscale: true)Go
r, _ := client.Compress(ctx, &snappdf.CompressInput{File: bytes, Level: "max", Grayscale: true})