PDF Compression API
Compress and optimize a PDF.
Feature
The ComPDF Self-hosted accepts files and a request JSON string through multipart/form-data, forwards the parameters to the private PDF SDK, and streams the result file back on success.
Synchronous Request
| Item | Value |
|---|---|
| Authentication | x-api-key: your_api_key_here |
| Request URL | POST http://localhost:8080/api/v1/process/pdf/compress |
| Content type | multipart/form-data |
| Success response | Result file stream |
Request Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
file | File | Source PDF file. | Yes |
request | String | JSON string containing the PDF SDK parameters below. If omitted, remaining non-file form-data fields are forwarded as the request object. | No |
Request Object Parameters
Put the following fields in the request JSON string.
| Parameter | Type | Purpose |
|---|---|---|
profile | String | Compression preset selector used by the middle layer. aggressive derives optimizeFlags from imageQuality when optimizeFlags is absent. |
optimizeFlags | String[] | Optimization actions. Presets may include flags such as RMEMBFONT, RMANNOT, RMDOCINFO, and RMMEDTADATA. |
imageQuality | Number | Compression image quality from 0 to 100. Presets use 30, 60, or 80. |
colorImageUpperPpi | Number | Color image maximum PPI. |
colorImageTargetPpi | Number | Color image target PPI. |
colorImageCompressAlgorithm | String | Color image compression algorithm, such as jpeg or flate. |
colorImageQuality | Number | Color image quality from 0 to 100. |
grayscaleImageUpperPpi | Number | Grayscale image maximum PPI. |
grayscaleImageTargetPpi | Number | Grayscale image target PPI. |
monochromeImageUpperPpi | Number | Monochrome image maximum PPI. |
monochromeImageTargetPpi | Number | Monochrome image target PPI. |
monochromeImageCompressAlgorithm | String | Monochrome image compression algorithm, such as jbig2 or flate. |
password | String | Source PDF open password. Some routes remove it before forwarding when the SDK endpoint does not accept it directly. |
outputFileName | String | Optional output filename. When present, it is used as the preferred download filename. |
Request Example
bash
curl -X POST "http://localhost:8080/api/v1/process/pdf/compress" \
-H "x-api-key: your_api_key_here" \
-F "[email protected]" \
-F 'request={"profile":"aggressive","optimizeFlags":"","imageQuality":60,"colorImageUpperPpi":"","colorImageTargetPpi":""}'Response
On success, the API returns the processed file stream with Content-Type and Content-Disposition headers. On failure, the ComPDF Self-hosted returns a normalized error JSON response.