# PDF Tools: Merge, Split, Rotate, Watermark and Images to PDF (`forgeloop/pdf-tools`) Actor

Merge, split, extract, delete, rotate and reorder PDF pages from URLs. Turn JPG and PNG images into a PDF, set or remove metadata, add a text watermark or page numbers, render pages to PNG and read PDF info. Direct file links in the output. Pay per produced file.

- **URL**: https://apify.com/forgeloop/pdf-tools.md
- **Developed by:** [Markus Heiß](https://apify.com/forgeloop) (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 $2.00 / 1,000 pdf produceds

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/running/actors-in-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, Rotate, Watermark and Images to PDF

Work with PDF files from URLs: merge several PDFs into one, split a PDF into parts, extract, delete, rotate or reorder pages, turn JPG and PNG images into a PDF, set or remove metadata, add a text watermark or page numbers, render pages to PNG, or just read the facts of a PDF (pages, sizes, version, metadata, encryption).

Every produced file is saved in the run's key-value store. Each dataset row holds a direct link to the file, its key, the page count and the size. Run one operation on many files, or several different operations in one run with a jobs list. Built for automations (Make, n8n, Zapier, the Apify API) and for AI agents that need to prepare documents.

The Actor works with plain JavaScript libraries ([pdf-lib](https://github.com/Hopding/pdf-lib) and [pdf.js](https://github.com/mozilla/pdf.js) through [unpdf](https://github.com/unjs/unpdf)). No browser, no external PDF service: your files are only downloaded from the URLs you give and processed inside the run.

### What it does

- **Merge:** combine 2 to 100 PDFs into one, in the order of the URLs. Title and author come from the first file.
- **Split:** one file per page, one file per range (`1-3,5,8-` gives three files) or one file per N pages.
- **Extract pages:** a new PDF with the selected pages in the given order. `9,1` puts page 9 first.
- **Delete pages:** a new PDF without the selected pages.
- **Rotate:** turn the selected pages by 90, 180 or 270 degrees clockwise. The rotation is added to the current one.
- **Reorder:** the pages you list come first, the rest follows in its old order. `5,1` moves page 5 to the front and page 1 behind it.
- **Images to PDF:** JPG and PNG images become one PDF, one image per page, on A4, Letter, Legal, A3, A5 or a page exactly as large as the image. Wide images get a landscape page. JPGs are embedded without recompression.
- **Metadata:** set title, author, subject and keywords, or remove all existing document information first (creator, producer, dates, custom fields and the XMP stream).
- **Watermark:** a text like `DRAFT` or `CONFIDENTIAL` across the middle of each selected page, with font size, angle, color and opacity.
- **Page numbers:** formats like `{n} / {total}` or `Page {n} of {total}`, six positions, a start number, and a page selection to skip a cover page.
- **Render to PNG:** the selected pages as PNG images at 36 to 300 DPI, up to 100 pages per file.
- **Info only:** page count, page sizes (points, millimetres, paper name, orientation), PDF version, file size, encrypted flag, metadata, form and XMP flags. No file is produced.
- **Rotated pages handled:** watermarks and page numbers are placed on the page as it is displayed, also on pages with a rotation.
- **Safe downloads:** http and https only, private and local network addresses are refused, every redirect is checked, size limit and timeout per file. Video and social platform links (YouTube, TikTok, Instagram, Vimeo and similar) are refused with a free error row.

### Use cases

- **Document automation:** merge an invoice with its terms, add page numbers and send the link on in Make or n8n.
- **Archiving:** split scanned batches into single documents or chunks of N pages.
- **Review copies:** stamp `DRAFT` or `CONFIDENTIAL` on contracts and reports before sharing them.
- **Clean up before publishing:** remove author names, software traces and old titles from PDF metadata, or set a proper title for search engines.
- **Photo and scan collection:** turn phone photos of receipts or delivery notes (JPG, PNG) into one A4 PDF.
- **Previews and thumbnails:** render the first page of each PDF to PNG for a website, a catalogue or an AI vision model.
- **PDF checks in pipelines:** read page count, page sizes, version and encryption before you process or print a file.

### Input

| Field | Description | Default |
|---|---|---|
| Operation | `merge`, `split`, `extract`, `delete`, `rotate`, `reorder`, `imagesToPdf`, `metadata`, `watermark`, `pageNumbers`, `info`, `render` | |
| URLs | Direct links to PDFs (or JPG and PNG images for `imagesToPdf`) | |
| Pages | Page selection like `1-3,5,8-`, `-3`, `odd`, `even`, `last`, `all` | all |
| Split every N pages | Split only, one file per N pages | |
| Rotation | `90`, `180` or `270` degrees clockwise | `90` |
| Page size, Orientation, Margin | Images to PDF: `A4`, `Letter`, `Legal`, `A3`, `A5`, `fit`; `auto`, `portrait`, `landscape`; margin in mm | `A4`, `auto`, 10 |
| Title, Author, Subject, Keywords | Metadata to set | |
| Remove existing metadata | Clear all document information and XMP first | off |
| Watermark text, angle, font size, opacity, color | Watermark settings | 45 degrees, 60 pt, 0.25, `#808080` |
| Page number format, position, first number | Like `Page {n} of {total}`, `bottom-center`, 1 | `{n} / {total}` |
| Render resolution | Render only, 36 to 300 DPI | 110 |
| Output file name | Base name of the output files | source file name |
| Jobs | Several operations in one run (JSON array) | |
| Max file size | Per download, 1 to 100 MB | 100 |
| Download timeout | Seconds per download | 120 |

Merge and images to PDF combine all URLs of a job into one file. All other operations run on each URL separately, so `rotate` with 10 URLs gives 10 rotated PDFs.

Example, merge two PDFs:

```json
{
  "operation": "merge",
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
    "https://bitcoin.org/bitcoin.pdf"
  ],
  "outputName": "combined"
}
```

Example, several operations in one run with a jobs list. Option names are the same as the form fields:

```json
{
  "jobs": [
    { "operation": "split", "urls": ["https://bitcoin.org/bitcoin.pdf"], "options": { "pages": "1-3,4-" } },
    { "operation": "watermark", "urls": ["https://www.irs.gov/pub/irs-pdf/fw9.pdf"], "options": { "watermarkText": "DRAFT", "color": "#CC0000" } },
    { "operation": "pageNumbers", "urls": ["https://bitcoin.org/bitcoin.pdf"], "options": { "pages": "2-", "pageNumberFormat": "Page {n} of {total}" } },
    { "operation": "info", "urls": ["https://www.irs.gov/pub/irs-pdf/fw9.pdf"] }
  ]
}
```

### Output

One dataset row per produced file:

```json
{
  "operation": "split",
  "jobIndex": 1,
  "sourceUrls": ["https://bitcoin.org/bitcoin.pdf"],
  "fileUrl": "https://api.apify.com/v2/key-value-stores/aBcD1234/records/01-split-bitcoin-p1-3.pdf?signature=cfZSq3zljOnvYAowh6dh",
  "key": "01-split-bitcoin-p1-3.pdf",
  "contentType": "application/pdf",
  "pages": 3,
  "bytes": 156318,
  "sourcePages": "1-3",
  "error": null
}
```

- `fileUrl` opens or downloads the file without an Apify token (the signature in the link allows access to this one record). It stays valid as long as the run's storage is kept (see your Apify data retention settings). `key` is the record name in the run's key-value store.
- `sourcePages` (split, extract, render) tells which pages of the source went into the file. Other operations add `removedPages`, `newOrder`, `rotatedPages`, `stampedPages`, `numberedPages` or the new `metadata`.
- Render rows have `contentType` `image/png` plus `width`, `height` and `dpi`.
- `jobIndex` is the number of the job. In the simple form each URL of a per-file operation is its own job.

The info operation returns one row per PDF and no file:

```json
{
  "operation": "info",
  "jobIndex": 1,
  "sourceUrls": ["https://www.irs.gov/pub/irs-pdf/fw9.pdf"],
  "bytes": 140815,
  "pdfVersion": "1.7",
  "encrypted": false,
  "pageCount": 6,
  "pageSizes": [
    { "widthPt": 611.98, "heightPt": 791.97, "widthMm": 215.9, "heightMm": 279.4, "paper": "Letter", "orientation": "portrait", "count": 6, "pages": "1-6" }
  ],
  "rotatedPages": null,
  "metadata": { "title": "Form W-9 (Rev. March 2024)", "author": "SE:W:CAR:MP", "subject": "Request for Taxpayer Identification Number and Certification", "keywords": "Fillable", "creator": "Designer 6.5", "producer": "Designer 6.5", "creationDate": "2024-03-06T13:18:13.000Z", "modificationDate": "2024-03-06T13:18:13.000Z" },
  "hasXmpMetadata": true,
  "hasForm": true,
  "error": null
}
```

- `pageSizes` groups pages of the same displayed size. `paper` is the name of a standard size (A3, A4, A5, Letter, Legal) or `null`.
- `pdfVersion` comes from the file header.

Errors get a row with `error` set and no file, for example `Page 12 does not exist. The PDF has 9 pages.`, `The URL did not return a PDF file but an HTML page.` or `File is larger than the limit of 100 MB`. Export the dataset as JSON, CSV or Excel, or read it through the Apify API.

### Pricing

- **PDF produced:** 0.002 USD per output file, so 2.00 USD per 1,000 files. Every PDF from merge, split, extract, delete, rotate, reorder, images to PDF, metadata, watermark and page numbers counts, and every PNG from render. A split into 20 parts is 20 files.
- **PDF analysed:** 0.0005 USD per info row.
- Errors, refused URLs, encrypted files and invalid jobs are free.

Example: merging 5 PDFs into one costs 0.002 USD. Splitting a 30 page PDF into single pages costs 0.06 USD. Set the maximum charge per run in Apify to cap the cost; the Actor stops before it would produce a file that is over the limit.

Each run also has a start fee of 0.00005 USD per GB of memory, which Apify shows as Actor Start.

### Limits

- At most 100 file downloads per run (all jobs together), 100 MB per file and 2,000 pages per PDF, also for a merged result. Render: at most 100 pages per file, very large pages are rendered at a lower DPI to stay under 40 megapixels. PNG images for images to PDF: at most 40 megapixels.
- **Encrypted PDFs** (password or permission protected) are not changed. They get a free error row. The Actor does not crack or remove passwords, and there is no password field because the PDF library cannot open encrypted files for editing. Info still reports page count and metadata when the file opens without a password.
- Split, extract, delete and merge build a new PDF from the pages. Page content, links on pages and annotations stay; document-level parts such as bookmarks, form logic and attachments are not carried over. Rotate, reorder, metadata, watermark and page numbers change the original file and keep everything else.
- Watermarks and page numbers use the built-in Helvetica font, so only Latin characters (Windows-1252) work. Other scripts get a clear error.
- Setting metadata removes the XMP metadata stream, so PDF viewers show the new values instead of old ones from XMP.
- No compression, OCR, form filling, signing or conversion from Office files.
- Only direct file links. Pages that need a login, a cookie banner or JavaScript to reach the file do not work.
- The default memory is 512 MB. In tests a merge of 7 files into a 926 page, 31 MB PDF peaked at about 320 MB. For files over 30 MB or merges of many large files, give the run 1 GB or more.

### Data source, permitted use and legal

- **Data source:** The files at the URLs you provide. The Actor downloads each file once, processes it inside the run and stores the results in your run's key-value store. It does not use any third-party PDF service.
- **Your files:** Produced files are stored in your Apify account under your data retention settings. Anyone with a `fileUrl` can open that file, so share links with care.
- **Snapshot:** Results reflect the files at the time of the run. We do not guarantee that processing is complete or correct for every PDF, especially damaged or unusual files.
- **For business use:** This Actor is offered to businesses only, not to consumers.
- **Permitted use:** Process only files you own or have the right to change and copy. Watermarks or removed metadata do not change who owns a document.
- **Your responsibility:** You choose the files and decide what happens with the results. If your files contain personal data, you are the controller and need your own legal basis.
- **No circumvention:** The Actor does not decrypt, crack or bypass passwords, permissions or DRM. Encrypted files are refused. It does not download from video or social platforms and does not get around logins or blocks.
- **Request volume:** One download at a time, with retries and backoff on HTTP 429 and 5xx (at most 3 retries). Do not use it to put excessive load on the servers that host your files.
- **Provider:** forgeloop, Markus Heiss, Austria. [Imprint](https://devhem.github.io/forgeloop-legal/imprint.html), [Privacy Notice](https://devhem.github.io/forgeloop-legal/privacy.html), [Terms of Use](https://devhem.github.io/forgeloop-legal/terms.html).

### Questions and issues

Open an issue on the Actor page.

# Actor input Schema

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

What to do with the files under URLs. Merge and images to PDF combine all URLs into one PDF in the given order. All other operations run on each URL separately.

## `urls` (type: `array`):

Direct links to PDF files (or JPG and PNG images for images to PDF). http and https only. Links to video or social platforms and private network addresses are refused. Format: a list of strings like \["https://example.com/report.pdf"].

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

Page selection like 1-3,5,8- (8- means page 8 to the end, -3 means pages 1 to 3). Also odd, even, last and all. Split: each comma separated part becomes one file, empty splits every page. Extract: the pages in the given order. Delete: the pages to remove. Reorder: the new order of the first pages, the rest follows in its old order. Rotate, watermark, page numbers and render: the pages to change, empty means all.

## `everyNPages` (type: `integer`):

Split only: one file per N pages, for example 10 gives pages 1-10, 11-20 and so on. Overrides Pages.

## `angle` (type: `string`):

Rotate only: degrees clockwise, added to the current rotation of each page.

## `pageSize` (type: `string`):

Images to PDF only: paper size of each page. Fit makes each page exactly as large as its image (1 pixel = 0.75 pt, like 96 dpi). Default A4.

## `orientation` (type: `string`):

Images to PDF only: auto turns the page to landscape for wide images. Default auto.

## `marginMm` (type: `number`):

Images to PDF: white margin around each image, default 10 (0 for fit). Page numbers: distance from the page edge, default 10. 0 to 50.

## `title` (type: `string`):

Metadata only: new document title.

## `author` (type: `string`):

Metadata only: new author, usually your organisation.

## `subject` (type: `string`):

Metadata only: new subject.

## `keywords` (type: `string`):

Metadata only: keywords separated by commas, like invoice, 2026, client.

## `removeMetadata` (type: `boolean`):

Metadata only: delete all existing document information (title, author, creator, producer, dates, custom fields) and the XMP metadata first. Fields above are then set on the clean file.

## `watermarkText` (type: `string`):

Watermark only: text drawn across the middle of each selected page, like DRAFT or CONFIDENTIAL. Latin characters only (built-in Helvetica font). Long texts shrink to fit the page.

## `watermarkAngle` (type: `integer`):

Watermark only: angle of the text in degrees, counterclockwise. 0 is horizontal. Default 45.

## `fontSize` (type: `number`):

Watermark: default 60. Page numbers: default 10.

## `opacity` (type: `number`):

Watermark only: 0.05 (almost invisible) to 1 (solid). Default 0.25.

## `color` (type: `string`):

Hex color like #FF0000. Watermark default #808080 (gray), page numbers default #333333.

## `pageNumberFormat` (type: `string`):

Page numbers only: text with {n} for the number and {total} for the last number, like Page {n} of {total}. Default {n} / {total}.

## `pageNumberPosition` (type: `string`):

Page numbers only: where the number goes on each page, as the page is displayed. Default bottom center.

## `startNumber` (type: `integer`):

Page numbers only: number of the first numbered page. With Pages set to 2- the cover stays unnumbered and page 2 shows this number. Default 1.

## `dpi` (type: `integer`):

Render only: resolution of the PNG files. 72 is screen size, 150 is good for reading, 300 for print. 36 to 300, default 110. At most 100 pages per file.

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

Base name for the output files. Empty uses the source file name. Keys look like 01-split-report-p1-3.pdf (job number, operation, name, pages).

## `jobs` (type: `array`):

Optional, replaces Operation and URLs. A JSON array of jobs, each with operation, urls and options, for example \[{"operation": "merge", "urls": \["https://a.com/1.pdf", "https://a.com/2.pdf"]}, {"operation": "watermark", "urls": \["https://a.com/3.pdf"], "options": {"watermarkText": "DRAFT", "pages": "1"}}]. Option names are the same as the fields of this form. Fields filled in the form act as defaults for every job.

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

Larger downloads are stopped and get a free error row. 1 to 100.

## `timeoutSecs` (type: `integer`):

Give up on a download after this many seconds. 10 to 600.

## Actor input object example

```json
{
  "operation": "merge",
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
    "https://bitcoin.org/bitcoin.pdf"
  ],
  "maxFileSizeMb": 100,
  "timeoutSecs": 120
}
```

# Actor output Schema

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

No description

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

No description

# 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": "merge",
    "urls": [
        "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
        "https://bitcoin.org/bitcoin.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("forgeloop/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": "merge",
    "urls": [
        "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
        "https://bitcoin.org/bitcoin.pdf",
    ],
}

# Run the Actor and wait for it to finish
run = client.actor("forgeloop/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": "merge",
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
    "https://bitcoin.org/bitcoin.pdf"
  ]
}' |
apify call forgeloop/pdf-tools --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,forgeloop/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/Vdy4YvHtCy6o8oLoc/builds/ijS2jBdTfLSUWflQP/openapi.json
