Compress PDF

Reduce the file size of PDF documents while maintaining acceptable quality.

POSThttps://api.morphopdf.com/v1/pdf/compress

Authentication

AuthorizationBearer

Retrieve your API Key from Dashboard.

Request Body

One input source is required (file, fileBase64, or url).

fileFile

The PDF file to compress, uploaded via multipart/form-data.

fileBase64string

Base64-encoded PDF content as an alternative to file upload.

urlstring

Public URL of PDF file to fetch and compress.

Compression Options

qualitystringOptionalDefault: low

Compression quality level: 'low', 'medium', or 'high'. Lower quality = smaller file size.

Quality Levels

LevelDescriptionDPIBest For
lowMaximum Compression50Archiving, email, smallest file
mediumBalanced100General use, screen reading
highHigh Quality150Printing, 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: json

Response 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):

successboolean

Indicates whether the operation completed successfully.

messagestring

Human-readable status message.

fileNamestring

Name of the compressed PDF file.

downloadUrlstring

Presigned URL to download the file. Valid for 1 hour.

originalSizenumber

Original file size in bytes.

compressedSizenumber

Compressed file size in bytes.

compressionRatiostring

Compression ratio as a percentage (e.g., '45.0%').

Error Responses

StatusCodeDescription
400INVALID_PDFInvalid or missing PDF file
400INVALID_QUALITYQuality must be 'low', 'medium', or 'high'
413FILE_TOO_LARGEFile exceeds maximum size (50MB)
500COMPRESSION_FAILEDInternal processing error
POST/v1/pdf/compress
curl -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
200OK
{
  "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%"
}