Compress PDF
Reduce the file size of PDF documents while maintaining acceptable quality.
https://api.morphopdf.com/v1/pdf/compressAuthentication
Retrieve your API Key from Dashboard.
Request Body
One input source is required (file, fileBase64, or url).
fileFileThe PDF file to compress, uploaded via multipart/form-data.
fileBase64stringBase64-encoded PDF content as an alternative to file upload.
urlstringPublic URL of PDF file to fetch and compress.
Compression Options
qualitystringOptionalDefault: lowCompression quality level: 'low', 'medium', or 'high'. Lower quality = smaller file size.
Quality Levels
| Level | Description | DPI | Best For |
|---|---|---|---|
low | Maximum Compression | 50 | Archiving, email, smallest file |
medium | Balanced | 100 | General use, screen reading |
high | High Quality | 150 | Printing, presentations |
Quality Naming
'low' quality results in the smallest file size (highest compression). The naming refers to output quality, not compression strength.
Query Parameters
formatstringOptionalDefault: jsonResponse format. Use 'binary' to receive the compressed PDF file directly, or 'json' (default) to receive metadata with a download URL.
Response
When using format=json (default):
successbooleanIndicates whether the operation completed successfully.
messagestringHuman-readable status message.
fileNamestringName of the compressed PDF file.
downloadUrlstringPresigned URL to download the file. Valid for 1 hour.
originalSizenumberOriginal file size in bytes.
compressedSizenumberCompressed file size in bytes.
compressionRatiostringCompression ratio as a percentage (e.g., '45.0%').
Error Responses
| Status | Code | Description |
|---|---|---|
| 400 | INVALID_PDF | Invalid or missing PDF file |
| 400 | INVALID_QUALITY | Quality must be 'low', 'medium', or 'high' |
| 413 | FILE_TOO_LARGE | File exceeds maximum size (50MB) |
| 500 | COMPRESSION_FAILED | Internal processing error |
/v1/pdf/compresscurl -X POST "https://api.morphopdf.com/v1/pdf/compress?format=binary" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@large.pdf" \
-F "quality=medium" \
--output compressed.pdf{
"success": true,
"message": "File processed successfully",
"fileName": "compressed.pdf",
"downloadUrl": "https://files.morphopdf.com/sessions/abc123/output/compressed.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=3600&...",
"originalSize": 2048576,
"compressedSize": 1126400,
"compressionRatio": "45.0%"
}