PDF Compress API - Reduce PDF File Size Programmatically
Reduce PDF file sizes through our compression API. Compress large documents by up to 95% while keeping them readable and usable. Choose from four compression levels to balance file size against quality, from light compression that keeps near-original quality to extreme compression for maximum size reduction.
The API compresses images, removes redundant data, optimizes fonts, and cleans up PDF structure without changing your content or layout. Handle files up to 1GB and pick the compression level that fits your needs. Use it to cut storage costs, meet email attachment limits, speed up downloads, or archive documents more efficiently.
Built for document management systems, email platforms, cloud storage services, mobile apps, and archival workflows. Automate compression in your pipelines with asynchronous processing and webhook notifications.
Features
Multiple Compression Levels
Select from low, balanced, high, or extreme compression modes. Extreme mode achieves up to 95% file size reduction by aggressively optimizing all compressible elements, perfect for archival storage and bandwidth-constrained environments.
Intelligent Optimization
Automatically compresses images, strips redundant data, optimizes embedded fonts, and streamlines PDF structure while preserving document layout, text clarity, and essential metadata.
Content-Aware Compression
Applies different compression techniques based on content type. Images use format-appropriate algorithms, vector graphics remain lossless, and text stays crisp across all compression levels.
Massive Storage Savings
Reduce infrastructure costs by integrating our compression API into your document pipeline. Lower S3, Azure Blob, or cloud storage usage and bandwidth costs by up to 90% for image-heavy documents, delivering immediate ROI on storage expenses.
Asynchronous Processing
Upon successful request, our API immediately returns a 200 OK response with a unique Task ID, processing your file in the background. You can track the task progress via our Task Status API using the unique Task ID.Webhook Notifications
If you don't want to poll for task status, you can simply provide the webhook data in your request. Instead of manually checking status, we will automatically notify your endpoint the moment the task processing is completed.
Zero Data Retention
Your privacy matters. When you set thedestroy parameter, your files are permanently wiped from our servers immediately after processing finishes, ensuring complete data security. If destroy is not set, files are retained up to 30 days based on user's plan.Large File Support
Handle heavy documents and high-resolution assets with ease. Our API supports a massive 1GB payload size per request, allowing you to process even the largest PDF files without worrying about size restrictions.
Need to quickly Compress PDF files in browser?
Quick, safe, and easy PDF compression in your browser-no downloads, installation, or sign-up. Choose from four levels to balance quality and size, with up to 95% reduction while keeping text sharp and layout intact.
API Endpoint
$ pip install requestsimport requests
url = "https://api.apifreaks.com/v1.0/pdf/compress?compression_level=balanced&output=compressed_pdf"
payload = {}
files=[
('file',('file.pdf',open('/path/to/file.pdf','rb'),'application/pdf'))
]
headers = {
'X-apiKey': 'API-KEY'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
Utility & Resource APIs
Use these endpoints to manage files and check task status.
Task Status API
task_id. The response includes creation and expiry timestamps to help you track result availability, along with specific error details if a task fails. Results are retained for up to 7 days, depending on the operation.File Status API
file_id. Returns details including file name, size, type, and creation/deletion timestamps. Generated or uploaded files are retained up to 30 days based on user's plan, unless destroy is enabled to delete them immediately. You can use this endpoint to check if the file has expired using its file_id.File Download API
PDF Delete API
Files List API
File Upload API
multipart/form-data request. Each file receives a unique file_id that can be used with the PDF APIs.Upload Binary API
file_id for uses with the PDF APIs.How-To-Guides
Optimizing Your PDF Compression
Use this quick reference to choose the right compression_level for your needs.
low(High Quality):- Best For: Legal contracts, blueprints, and professional portfolios.
- Result: Minimal reduction (~10-20%), maximum visual fidelity. Removes only redundant metadata.
balanced(Recommended):- Best For: General business documents, reports, and presentations.
- Result:Significant reduction (~40-60%) with excellent visual quality. The “Safe Choice” for most users.
high(Web Ready):- Best For: Website assets, email attachments, and mobile viewing.
- Result: Strong reduction. Images are downsampled slightly to fit bandwidth constraints.
extreme(Max Storage Savings):- Best For: Long-term archiving, thumbnails, or internal records.
- Result: Maximum reduction (~80-90%). Images may show visible compression artifacts, but text remains sharp.
Compress PDF File
Step 1: Upload and Compress PDF
Reduce your PDF file size by specifying your desired compression level. This example uses balanced mode, which provides the best trade-off between file size and visual quality for standard business documents.
# Standard Response { "taskId": "04a06cd5-158d-4191-a45b-6f58249c599d", "inputIds": [ "7a9e4b12-f3c8-4d56-b7e1-8c2f9d0a3e6f" ] } # Response with destroy=true (No File IDs as they are deleted right away) { "taskId": "04a06cd5-158d-4191-a45b-6f58249c599d" }curl -X 'POST' \ 'https://api.apifreaks.com/v1.0/pdf/compress?compression_level=balanced&output=optimized_doc' \ -H 'X-apiKey: YOUR_API_KEY' \ -F 'file=@/path/to/file.pdf'
Step 2: Check Task Status
After submitting a compression task, check its progress using the Task Status API with your taskId. The task goes through these statuses: queued, processing, completed, and failed.
# Response (completed) { "taskId": "a1b2c3d4-e5f6-7890-a1b2-c3d4e5f67890", "status": "completed", "createdAt": "2025-01-26 10:30:00", "outputUrls": [ "https://api.apifreaks.com/v1.0/pdf/resource/download?resource_id=9b2e7f3a-5c8d-4e1b-a6f9-0d3c8e7b2a5f" ], "outputFileId": [ "9b2e7f3a-5c8d-4e1b-a6f9-0d3c8e7b2a5f" ], "inputIds": [ "7a9e4b12-f3c8-4d56-b7e1-8c2f9d0a3e6f" ], "expiresAt": "2025-01-27 10:30:00" }curl -X GET "https://api.apifreaks.com/v1.0/pdf/task-status?task_id=a1b2c3d4-e5f6-7890-a1b2-c3d4e5f67890" \ -H "X-apikey: YOUR_API_KEY"
# Response (failed) { "taskId": "a1b2c3d4-e5f6-7890-a1b2-c3d4e5f67890", "status": "failed", "createdAt": "2025-01-26 10:30:00", "inputIds": [ "7a9e4b12-f3c8-4d56-b7e1-8c2f9d0a3e6f" ], "error": "Invalid PDF File", "message": "The provided file is not a valid PDF file.", "expiresAt": "2025-01-27 10:30:00" }curl -X GET "https://api.apifreaks.com/v1.0/pdf/task-status?task_id=a1b2c3d4-e5f6-7890-a1b2-c3d4e5f67890" \ -H "X-apikey: YOUR_API_KEY"
Step 3: Download Compressed PDF
Once the task status shows “completed”, download your compressed PDF using the File Download API with the outputFileId from the task status response.
curl -X GET "true?resource_id=a7b8c9d0-e1f2-3456-a7b8-c9d0e1f23456" \ -H "X-apikey: YOUR_API_KEY" \ --output optimized_doc.pdf
Webhook Support
Get automatic notifications when your task completes instead of polling the task status endpoint. Good for event-driven applications and real-time document processing.
Add webhook_urlto your request. We'll send a POST request to this URL when the task finishes (either completed or failed).
See the Complete Webhook Example section below for a full demonstration including custom authorization headers.
Webhook Delivery
Webhook delivery will be attempted up to 3 times. If all retries fail and webhook_failure_notificationis enabled, we'll send an email notification to the requesting user or their organization admin.
Custom Authorization Header
Use X-Webhook-Authorization to add a custom header to webhook requests for endpoint security.
Format: Key:Value
Example: If you send Authorization:Bearer token123, the webhook request will include: Authorization: Bearer token123
See the Complete Webhook Example below for a full demonstration.
Complete Webhook Example
Here's a complete example showing webhook integration with custom authorization header and failure notifications:
# Response { "taskId": "04a06cd5-158d-4191-a45b-6f58249c599d", "inputIds": [ "566dc743-d8fe-4943-8cef-61e5d3d6096c" ] }curl -X 'POST' \ 'https://api.apifreaks.com/v1.0/pdf/compress?webhook_url=https://yourdomain.com/webhook/pdf-compress&webhook_failure_notification=true' \ -H 'X-apiKey: YOUR_API_KEY' \ -H 'X-Webhook-Authorization: Authorization:Bearer token123' \ -F 'file=@/path/to/document.pdf'
Webhook Request Format
When your task completes, we send a POST request to your webhook_url with these headers:
| Header | Description |
|---|---|
Content-Type | Always application/json |
X-Signature | HMAC-SHA256 signature of the request body using your API key. Use this to verify the payload is authentic. |
| Custom Header | (If provided) Your custom header from X-Webhook-Authorization |
Webhook Response
The webhook payload contains the same response structure as the Task Status API endpoint when checked for the task ID.
Verifying Webhook Authenticity
Use the X-Signatureheader to verify webhook requests actually came from API Freaks and weren't tampered with.
How the signature works:
- We compute an HMAC-SHA256 hash of the request body using your API key as the secret
- We Base64-encode the result
- We send this as the
X-Signatureheader value
To verify the webhook:
- Take the raw payload body (JSON string exactly as received without parsing it)
- Compute HMAC-SHA256 of the payload using your API key as the secret
- Base64-encode the result of the hash
- Compare with the
X-Signatureheader value
Important:Don't transform or process the raw request body before verification. Adding whitespace or other formatting creates a different signature and verification will fail.
Pricing
To use this PDF Compress API, API credits are required. Charges apply only for successful queries, defined by a 2xx status code. If a request results in a 4xx or 5xx status code, no credits will be deducted, and any credits already charged will be refunded. In the event of a Task Processing Error, a maximum of 200 credits will be refunded. Surcharges for additional file sizes are non-refundable.
For each successful request, 200 credits will be charged. 1 extra credit will be charged per MB beyond 50 MB.
Utilize the Credits Usage API to efficiently monitor your recent consumption of both one-off and subscription credits. This API provides a streamlined way to track and manage your credit usage, ensuring you stay informed about your remaining balance and can optimize your resource allocation effectively.