# PDF Tools - Merge, Split, Compress, Rotate & Extract in Bulk (`northbell/pdf-tools`) Actor

Merge PDFs, split them into pages or ranges, extract or rotate pages, compress and read PDF info, from links or another Actor's dataset. Results are files with public links. Built for n8n, Make, Zapier and AI agents.

- **URL**: https://apify.com/northbell/pdf-tools.md
- **Developed by:** [Northbell](https://apify.com/northbell) (community)
- **Categories:** Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.60 / 1,000 files

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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 Tools - Merge, Split, Compress, Rotate & Extract in Bulk

**Merge, split, extract, rotate and compress PDF links in bulk, or read their page count and metadata.** Give it direct links to PDFs (or a dataset from another Actor) and get result PDFs back as files with public links, one dataset row per file. One bad PDF never fails the run: it becomes a row with a plain error message, and the rest carry on.

**Try it now — the input is already filled in.** Press **Start**. It splits two US government forms (IRS Form W-9, 6 pages, and IRS Form 1040, 2 pages; US federal government publications, public domain) and keeps pages 1-2 of each. In our own local run with this input (22 Nov 2026): **2 PDFs in (140,815 and 220,237 bytes), 2 PDFs out (40,262 and 112,464 bytes), about 7 seconds** including the downloads. That is 2 output files: **$0.004** (plus $0.00005 for the run start). Merging the same two forms into one 8-page PDF took about 16 seconds and came out at 168,657 bytes.

### What you pay

| Event | Price | When |
| --- | --- | --- |
| `file` | $0.002 | per output PDF stored (a merged file, each split part, an extracted, rotated or compressed file) |
| `info` | $0.0003 | per PDF read with the `info` operation |
| `apify-actor-start` | $0.00005 | once per run |

- You are charged for a file only after it is saved. Errors, rejected links, files skipped by "Only new files", and a compress that could not make the file smaller are free.
- A split that makes 10 parts is 10 files, $0.02.
- Set "Maximum total charge" on the run as your cap. The Actor checks the charge limit before it stores each file and stops cleanly when the next one does not fit.

### Operations

| `operation` | What it does |
| --- | --- |
| `merge` | All links (in the order given) become one PDF. A link that fails gets an error row and is left out; the others still merge. |
| `split` | Each PDF becomes several files: one per range in `ranges` (`1-3,5,7-`), else one per `everyN` pages, else one per page. |
| `extract` | Keeps the pages listed in `pages`, in the order written, as one new PDF. |
| `rotate` | Turns the pages in `pages` (all pages if empty) by `rotateDegrees` (90, 180 or 270), added to the rotation they already have. |
| `compress` | Re-saves the file with object streams and, if you leave `compressLevel` on `ebook`, `screen` or `printer`, downsamples images with Ghostscript. The smallest result wins. If nothing is smaller than the original, the original is kept: the row says `unchanged`, nothing is stored and nothing is charged. |
| `info` | One row per PDF: page count, size in bytes, title, author, subject, creator, producer, PDF version and whether it is encrypted. |

Page lists use 1-based numbers: `1-3,5,7-` means pages 1 to 3, page 5, and page 7 to the end. A page that does not exist (page 9 of a 5-page file) is an error row for that file, free. A list that cannot be read (`5-3`, `0`, `a`) stops the run before anything is charged.

**Password-protected PDFs are not supported.** Every operation except `info` returns an error row for them ("password-protected PDFs are not supported"), free. `info` still answers, with `encrypted: true`, and charges its normal price.

### Built so that runs finish

- **A timeout on every file.** Downloads give up after 20 seconds without data or 60 seconds in total; download plus PDF work is cut off at 240 seconds. A hung server costs you one error row, not the run.
- **Retries.** A 429, a 5xx answer or a dropped connection is tried again twice (after 1 and 3 seconds, or the server's `Retry-After` up to 10 seconds). A 404, a login page or a corrupt file is an error straight away.
- **Errors are rows.** Each failed file gets `status: "error"` and a sentence that says why (for example "The server answered 404." or "The file is not a PDF"). The run still ends as succeeded.
- **Bounded parallelism.** 3 files at a time. Merge downloads its inputs one after the other and holds them in memory together (up to 500 MB in total).
- **Size caps.** Inputs above `maxFileMb` (100 MB by default) and results above it are refused.

### Run it after your scraper or downloader

If another Actor collects PDF links (a document scraper, a government-portal scraper, a downloader), this Actor can process them automatically after every run of it:

1. In Apify Console, open that Actor and go to **Integrations**.
2. Add **Run Actor** (on "Run succeeded") and pick this Actor.
3. Use an input like this, with the name of the field that holds the PDF link or links:

```json
{
  "operation": "info",
  "datasetId": "{{resource.defaultDatasetId}}",
  "urlField": "pdfUrl",
  "onlyNew": true
}
```

Each run of the first Actor then hands over its dataset, and every link in it is used. The field can hold one link or a list of links; a dotted path such as `documents.file` reaches into nested fields, and a list of objects with a `url` field works too. For `merge`, the dataset links are merged in dataset order (links in `pdfUrls` come first). If the dataset has no links, nothing runs and nothing is charged. Each output row keeps a small `sourceItem` (the field name, the link and the row's `id` if it has one) so you can match results to the original rows.

### Run it on a schedule with only new files

Turn on `onlyNew` and schedule the run. The Actor keeps a list of what it has done in a key-value store named `pdf-tools-seen` in your account, keyed by a hash of the link, the operation and the settings that change the output (ranges, pages, degrees, level, output name). On the next run, files already done the same way come back as `status: "skipped"` rows and are not charged; change the operation or its settings and the files are processed again. For `merge` the key covers the whole ordered list of links, so a new link in the list means a new merge. Files that were not processed (for example because of `maxItems` or a charge limit), and files with an error, are not marked as done, so the next run picks them up. The list is saved at the end of the run. If the store cannot be opened, the run stops before charging anything.

### Input

| Input | Default | What it does |
| --- | --- | --- |
| `operation` | `split` | `merge`, `split`, `extract`, `rotate`, `compress` or `info` |
| `pdfUrls` | two IRS forms | direct links to PDF files |
| `datasetId`, `urlField` | - , `url` | read links from another Actor's dataset; dotted paths and lists allowed |
| `ranges` | `1-2` | split: one file per range, for example `1-3,5,7-` |
| `everyN` | none | split, when `ranges` is empty: one file per N pages |
| `pages` | none | extract: pages to keep (required); rotate: pages to turn (empty = all) |
| `rotateDegrees` | 90 | 90, 180 or 270 |
| `compressLevel` | `ebook` | `screen` (smallest), `ebook`, `printer` (best quality), or `none` (only re-save the structure) |
| `outputName` | none | name for the result files (merge: `<name>.pdf`, default `merged.pdf`) |
| `onlyNew` | off | skip files already done with the same operation and settings |
| `maxItems` | 200 | input PDFs per run (links and dataset together) |
| `maxFileMb` | 100 | largest input and largest result in MB (hard cap 300) |

Notes:

- **Split limit.** One PDF makes at most 1,000 files in a split; beyond that the file gets an error row and you are asked to use `ranges` or a larger `everyN`.
- **Compress.** Image downsampling needs Ghostscript, which is installed in this Actor's image (Alpine's own package, AGPL-3.0, unmodified, run as a separate program; its source is at https://ghostscript.com/releases/). The levels are Ghostscript's own: `screen` about 72 dpi, `ebook` about 150 dpi, `printer` about 300 dpi. Downsampling lowers the quality of images by design; use `printer` or `none` if that matters. A text-only PDF that was already saved compactly often cannot get smaller; that is the `unchanged` result.
- **What is kept.** Pages are copied with their text, images and fonts. Document-level extras such as interactive form fields, bookmarks and tags may not carry over into split, extracted or merged files, so do not rely on them. For split, extract and merge, the original's title and author are not copied (the new files carry no title or author); rotate and compress keep them.

### Output

One dataset row per result file (or per input that failed, was skipped or was unchanged). Each result file is stored in the run's key-value store, and `outputUrl` is its public link.

```json
{
  "inputUrl": "https://www.irs.gov/pub/irs-pdf/fw9.pdf",
  "operation": "split",
  "status": "ok",
  "error": null,
  "note": null,
  "outputUrl": "https://api.apify.com/v2/key-value-stores/57881fb7-fab8-47be-8668-faf3cbc3def1/records/fw9-f4fbd1d6-p1-2.pdf",
  "outputKey": "fw9-f4fbd1d6-p1-2.pdf",
  "pageRange": "1-2",
  "inputPages": 6,
  "outputPages": 2,
  "inputBytes": 140815,
  "outputBytes": 40262,
  "savedPercent": null,
  "method": null
}
```

This row is from our local run of the prefilled input; the store id in the link is the one that run used on our machine. On Apify it is your run's store. `status` is `ok`, `error`, `skipped` or `unchanged` (compress could not make the file smaller). For compress, `savedPercent` and `method` (`object-streams` or `ghostscript-ebook` and so on) are filled in. For a merge, the row has `sourceUrls` and `inputCount`, and `inputUrl` is `null`. For `info`, the row has `title`, `author`, `subject`, `creator`, `producer`, `pdfVersion` and `encrypted`. The result files stay as long as your Apify storage retention keeps the run.

### Limits

- Direct PDF links only. A link that returns a web page is an error (free). Links to private or local network addresses are rejected.
- The PDF must be reachable without a login. Some sites block automated downloads; those links come back as errors with the server's answer.
- No password-protected PDFs, no OCR, no filling of forms, no repair of badly damaged files.
- Your PDFs are processed only inside this Actor's run on Apify; nothing is sent to other services.
- You are responsible for having the right to process the PDFs you give it.

### 日本語

PDF への直リンク(または他の Actor のデータセット)を、結合・分割・ページ抽出・回転・圧縮して、公開リンク付きのファイルで返します。ページ数・サイズ・タイトル・作成者・暗号化の有無を読む info も用意。ページ指定は `1-3,5,7-` の形式。パスワード付き PDF は非対応(エラー行・無料)。圧縮は Ghostscript で画像を縮小し、小さくならなければ元のファイルのまま(無料)。保存できたファイル1つにつき $0.002、info は1件 $0.0003。失敗・スキップは無料です。`onlyNew` で前回までに処理済みのファイルをスキップできるので、スクレイパーの後や定期実行にも使えます。処理する PDF の権利はご自身でご確認ください。

# Actor input Schema

## `operation` (type: `string`):

What to do with the PDFs. Merge makes one file from all links in the order given; every other operation works on each link separately.

## `pdfUrls` (type: `array`):

Direct links to PDF files. Or leave empty and give a Dataset ID. For merge, the order here is the order in the merged file (dataset links come after these).

## `datasetId` (type: `string`):

Read PDF links from this Apify dataset (e.g. the dataset of a scraper or downloader run). Use {{resource.defaultDatasetId}} when you connect this Actor as an integration after another Actor.

## `urlField` (type: `string`):

Name of the field that holds the PDF link. A dotted path works (files.url). The field may hold one link or a list of links; every link is used.

## `ranges` (type: `string`):

Split only: one output file per range, for example 1-3,5,7- (pages start at 1; 7- means page 7 to the end). Empty: use Every N pages, or one file per page.

## `everyN` (type: `integer`):

Split only, when Page ranges is empty: one file per N pages (for example 10). Empty: one file per page. At most 1,000 files from one PDF.

## `pages` (type: `string`):

Extract: the pages to keep, in the order written, for example 1-3,5,7-. Rotate: the pages to turn (empty means all pages).

## `rotateDegrees` (type: `string`):

Rotate only. Added to the rotation the page already has.

## `compressLevel` (type: `string`):

Compress only. Images are downsampled with Ghostscript at this level. If the result is not smaller, the original is kept and nothing is charged.

## `outputName` (type: `string`):

Optional name for the result files (without .pdf). Merge: the merged file is called this (default merged.pdf). Other operations: used instead of the input's file name.

## `onlyNew` (type: `boolean`):

Skip links this Actor already handled with the same operation and settings in an earlier run (kept in a key-value store named pdf-tools-seen in your account). Use it for scheduled runs. Skipped files are free.

## `maxItems` (type: `integer`):

Cap on input PDFs per run, counting the links above and the dataset together (files skipped by Only new files do not count). Files over the cap are left for the next run.

## `maxFileMb` (type: `integer`):

Larger inputs, and results larger than this, come back as errors, free. Hard cap 300.

## Actor input object example

```json
{
  "operation": "split",
  "pdfUrls": [
    "https://www.irs.gov/pub/irs-pdf/fw9.pdf",
    "https://www.irs.gov/pub/irs-pdf/f1040.pdf"
  ],
  "urlField": "url",
  "ranges": "1-2",
  "rotateDegrees": "90",
  "compressLevel": "ebook",
  "onlyNew": false,
  "maxItems": 200,
  "maxFileMb": 100
}
```

# Actor output Schema

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

Status, result link, pages and sizes per input.

# 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 = {
    "operation": "split",
    "pdfUrls": [
        "https://www.irs.gov/pub/irs-pdf/fw9.pdf",
        "https://www.irs.gov/pub/irs-pdf/f1040.pdf"
    ],
    "ranges": "1-2"
};

// Run the Actor and wait for it to finish
const run = await client.actor("northbell/pdf-tools").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 = {
    "operation": "split",
    "pdfUrls": [
        "https://www.irs.gov/pub/irs-pdf/fw9.pdf",
        "https://www.irs.gov/pub/irs-pdf/f1040.pdf",
    ],
    "ranges": "1-2",
}

# Run the Actor and wait for it to finish
run = client.actor("northbell/pdf-tools").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 '{
  "operation": "split",
  "pdfUrls": [
    "https://www.irs.gov/pub/irs-pdf/fw9.pdf",
    "https://www.irs.gov/pub/irs-pdf/f1040.pdf"
  ],
  "ranges": "1-2"
}' |
apify call northbell/pdf-tools --silent --output-dataset

```

## MCP server setup

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

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/28l0ACXIuZ4PVeOb9/builds/IMWyJMywBDjNtEb4M/openapi.json
