# PDF Compressor (Bulk, keeps text) (`toowl/pdf-compressor`) Actor

Shrink PDFs in bulk from URLs. Downsamples and re-encodes embedded photos, recompresses streams and packs objects, while text stays real, selectable text. Pay per PDF.

- **URL**: https://apify.com/toowl/pdf-compressor.md
- **Developed by:** [Chalid Ade](https://apify.com/toowl) (community)
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 pdfs compressed

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## PDF Compressor — bulk, keeps text selectable

Shrink PDFs in bulk from a list of URLs. Embedded photos are downsampled and re-encoded, every other stream is recompressed, and objects are packed into compressed object streams. **Text stays real, selectable, searchable text** — pages are never flattened into images like many online compressors do.

Typical results: scanned or photo-heavy PDFs get **60–95% smaller**; text-only PDFs get a few percent smaller (and are never made bigger — if a file can't be improved you get the original back and `alreadyOptimal: true`).

### Why use it

- **Bulk**: hundreds of PDFs in one run, processed in parallel.
- **Keeps quality where it matters**: text, vector graphics, fonts and links are untouched; only photos are resampled.
- **Four presets** plus fine control over max image size and JPEG quality.
- **Password-protected PDFs** supported (give the password).
- **No third-party API**: the PDF is processed inside the run with qpdf and libvips. Nothing is sent anywhere else.
- **Pay only for PDFs that worked.** Failed downloads or broken files are reported but not charged.

### Input

| Field | What it does |
| --- | --- |
| `files` | PDF URLs (public links, S3/GCS presigned URLs, Dropbox `?dl=1`, Google Drive direct links…) |
| `level` | `light` (print, max 2400 px, q82), `medium` (email/web, 1600 px, q70 — default), `strong` (1100 px, q55), `extreme` (800 px, q40) |
| `maxImageSide`, `jpegQuality` | Override the preset |
| `password` | Password for protected PDFs (output is saved without a password) |
| `maxFileSizeMb` | Skip files above this size (default 100 MB) |

```json
{
  "files": [{ "url": "https://example.com/report.pdf" }],
  "level": "medium"
}
```

### Output

Each compressed PDF is saved in the run's key-value store. The dataset has one row per input file:

```json
{
  "url": "https://example.com/report.pdf",
  "name": "report.pdf",
  "downloadUrl": "https://api.apify.com/v2/key-value-stores/…/records/0001-report.pdf",
  "sizeBefore": 3435577,
  "sizeAfter": 193430,
  "savedPercent": 94.4,
  "imagesFound": 3,
  "imagesShrunk": 3,
  "alreadyOptimal": false
}
```

Failed files get a row with `error` instead (and are not charged). A `SUMMARY` record in the key-value store counts ok/failed files.

### Use it from code, Zapier, Make or n8n

Call the Actor through the [Apify API](https://docs.apify.com/api/v2) or the official integrations: e.g. compress every PDF that lands in a Google Drive folder or an S3 bucket, then email the `downloadUrl`.

```bash
curl -X POST "https://api.apify.com/v2/acts/<username>~pdf-compressor/run-sync-get-dataset-items?token=$APIFY_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"files":[{"url":"https://example.com/report.pdf"}],"level":"strong"}'
```

### Pricing

Pay per event: you pay a small fee per successfully compressed PDF (see the Pricing tab), no subscription. Set "Max cost per run" to cap any run — the Actor stops cleanly when the budget is reached.

### Limits

- What gets smaller: 8-bit RGB/grayscale JPEG photos, plus every compressible stream. CMYK and other special colour spaces, and lossless (PNG-style) images, are kept as they are.
- Very large PDFs need memory: give the run ~4× the file size (1 GB covers files up to ~200 MB).

### Want it in the browser instead?

The same engine runs free in your browser at [toowl.my.id/en/compress-pdf](https://toowl.my.id/en/compress-pdf/) — nothing uploaded.

### Use it from AI agents (MCP)

Add this Actor as a tool to Claude, Cursor, VS Code or any MCP client through Apify's MCP server:

```
https://mcp.apify.com/?actors=toowl/pdf-compressor
```

The agent can then pass file URLs and read the results itself.

### More toowl file APIs

Speech to text & subtitles, AI vocal remover, text to speech, AI object remover, PDF to Markdown, PDF to Word & Excel, HTML/URL to PDF, OCR, Office to PDF, PDF compressor, PDF merge/split, PDF password protect, PDF to image, image to PDF, bulk watermark, image converter and compressor, background remover, AI upscaler, image to SVG, QR code and barcode generators, QR/barcode reader, favicon generator, video compressor, frame extractor and audio converter. All pay per file, all batch-friendly: [toowl.my.id/en/api](https://toowl.my.id/en/api/).

Questions or a format that fails? Open an issue on the Actor's **Issues** tab.

# Actor input Schema

## `files` (type: `array`):

Direct links to the PDFs to compress (public URLs, Google Drive/Dropbox direct-download links, S3 presigned URLs…).

## `level` (type: `string`):

light = max 2400 px, JPEG q82 (print). medium = 1600 px, q70 (email, web). strong = 1100 px, q55 (smallest that still reads well). extreme = 800 px, q40.

## `maxImageSide` (type: `integer`):

Overrides the level: longest side of each embedded photo after compression.

## `jpegQuality` (type: `integer`):

Overrides the level: 1–100.

## `password` (type: `string`):

For password-protected PDFs (same password for every file). The output is saved without a password.

## `maxFileSizeMb` (type: `integer`):

Larger files are skipped with an error (not charged).

## Actor input object example

```json
{
  "files": [
    {
      "url": "https://raw.githubusercontent.com/chalidade/tools/main/apify/samples/sample.pdf"
    }
  ],
  "level": "medium",
  "maxFileSizeMb": 100
}
```

# Actor output Schema

## `results` (type: `string`):

One row per input file, with a download link for the result where there is one.

## `files` (type: `string`):

Result files in the default key-value store, plus a SUMMARY record.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "files": [
        {
            "url": "https://raw.githubusercontent.com/chalidade/tools/main/apify/samples/sample.pdf"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("toowl/pdf-compressor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "files": [{ "url": "https://raw.githubusercontent.com/chalidade/tools/main/apify/samples/sample.pdf" }] }

# Run the Actor and wait for it to finish
run = client.actor("toowl/pdf-compressor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "files": [
    {
      "url": "https://raw.githubusercontent.com/chalidade/tools/main/apify/samples/sample.pdf"
    }
  ]
}' |
apify call toowl/pdf-compressor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,toowl/pdf-compressor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/BFeSkHgSlMpLfIYYD/builds/bg48JFqWfitZQALy7/openapi.json
