# Merge PDF API: Combine PDFs with Page Ranges (`ferrolark/pdf-merge-api`) Actor

Merge PDF API to combine up to 20 PDFs from URLs or base64 into one file, in order, with page ranges, bookmarks and a manifest (pages, bytes, SHA-256). Built for n8n, Make, Zapier and AI agents. $0.005 per merge.

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

## Pricing

$5.00 / 1,000 merge completeds

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 Merge API: Combine PDFs with Page Ranges

Send a list of PDFs as URLs or base64 and get one merged PDF back. Files are merged in the order given, with optional page ranges per file, one bookmark per source file and a manifest with pages, bytes and SHA-256 for the output and every input.

It runs as a plain API call, so you don't need to install Stirling, add community nodes or sign up for a PDF service. It is built for n8n, Make, Zapier, scripts and AI agents.

### Real example

This input:

```json
{
  "files": [
    {"url": "https://arxiv.org/pdf/1706.03762", "pages": "1-2", "name": "Attention Is All You Need (pages 1-2)"},
    {"url": "https://www.irs.gov/pub/irs-pdf/fw9.pdf", "pages": "1", "name": "IRS Form W-9 (page 1)"},
    {"url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf", "name": "W3C dummy PDF"}
  ],
  "outputFileName": "research-pack.pdf",
  "title": "Research pack"
}
```

produced a 4-page, 240,269-byte PDF with three bookmarks.

- Run time: 4.0 s on Apify at 512 MB, including downloading 2.4 MB of input.
- Platform usage: $0.0002.
- Your price: **$0.005**.

The run's dataset item:

```json
{
  "fileName": "research-pack.pdf",
  "recordKey": "research-pack.pdf",
  "downloadUrl": "https://api.apify.com/v2/key-value-stores/<store-id>/records/research-pack.pdf",
  "pages": 4,
  "bytes": 240269,
  "sha256": "bbff8da01a3b20ae8d601c140270220b6ee0787c86c1edaa2828f2f93fa45a92",
  "inputs": [
    {
      "name": "Attention Is All You Need (pages 1-2)",
      "source": "https://arxiv.org/pdf/1706.03762",
      "bytes": 2215244,
      "sha256": "bdfaa68d8984f0dc02beaca527b76f207d99b666d31d1da728ee0728182df697",
      "pagesInFile": 15,
      "pagesUsed": [1, 2],
      "outputPages": [1, 2],
      "encrypted": false,
      "signed": false
    },
    {"name": "IRS Form W-9 (page 1)", "pagesInFile": 6, "pagesUsed": [1], "outputPages": [3, 3], "...": "..."},
    {"name": "W3C dummy PDF", "pagesInFile": 1, "pagesUsed": [1], "outputPages": [4, 4], "...": "..."}
  ],
  "warnings": [
    "IRS Form W-9 (page 1): has form fields; fields are kept on their pages but may lose document-level form settings."
  ]
}
```

The same input gives a byte-identical file (same SHA-256) on every run, so you can deduplicate or verify outputs.

### Price and limits

- **$0.005 per successful merge.**
  - There is no start fee or per-page fee.
  - Invalid input is not charged: a broken URL, a non-PDF file, a wrong password or a limit exceeded fails the run with "Not charged: …".
- Limits per run, which may be raised later:
  - 20 input files;
  - 20 MB of input in total;
  - 100 pages in the output.
- Use a single file with a page range to extract pages, for example `"pages": "2-5"`. It costs the same as a merge.

### Input

| Field | What it does |
|---|---|
| `pdfUrls` | Simple list of PDF URLs, merged in order. |
| `files` | Advanced list, merged after `pdfUrls`. Each item has `url` or `base64`, plus optional `pages`, `name` and `password`. |
| `files[].pages` | Page ranges, 1-based, in the order written: `"1-3,5,8-"`, `"last"`, `"3-1"` (reversed). Empty means all pages. |
| `files[].base64` | The PDF itself, as base64 or a `data:application/pdf;base64,…` URL. Use it for n8n and Make binaries. Keep the whole input under about 9 MB; use URLs for bigger files. |
| `outputFileName` | Record key of the merged file (default `merged.pdf`). |
| `addBookmarks` | One outline entry per input file (default on). The bookmark text is `name`, or the file name from the URL. |
| `title` | PDF metadata title. |
| `password` | Secret field, used for encrypted inputs that have no `password` of their own. |
| `createShareableUrl` | Also return a signed link that works without a token (default off). |

### Output and privacy

- The merged PDF is saved in the run's own key-value store.
- `downloadUrl` is the API URL of that record, which needs your Apify token. By default nothing is publicly reachable.
- Turn on `createShareableUrl` only if you need a link to hand to someone else. Anyone with that link can download the file.
- Files are processed only to merge them:
  - no text extraction and no OCR;
  - no logging of file contents;
  - the files are not used for anything else.
- Run storage follows your Apify data retention settings. Delete the run's storage when you no longer need it.

### How it works

- Merging uses [pypdf](https://github.com/py-pdf/pypdf) (BSD license).
- Pages are copied with their content, fonts, images, links and annotations.
- Security:
  - Document-level JavaScript is never copied.
  - Automatic page actions (`/AA`) are removed, and a warning says so.
  - Downloads are limited to public addresses (private and local IPs are refused).
- **Encrypted PDFs** are opened with the password you pass, or with an empty password if they only restrict printing or copying. The output is not encrypted.
- **Digitally signed PDFs** can be merged, but merging rewrites the file, so the signature will not be valid in the output. The `warnings` field says so for each signed input.
- **Form fields** stay on their pages. Document-level form settings may change, and you get a warning.

### Call it from code, n8n or an AI agent

**API (synchronous, returns the manifest):**

```bash
curl -X POST "https://api.apify.com/v2/acts/ferrolark~pdf-merge-api/run-sync-get-dataset-items?maxTotalChargeUsd=0.01" \
  -H "Authorization: Bearer $APIFY_TOKEN" -H "Content-Type: application/json" \
  -d '{"pdfUrls": ["https://example.com/a.pdf", "https://example.com/b.pdf"]}'
## then download the file (same token):
curl -H "Authorization: Bearer $APIFY_TOKEN" -o merged.pdf "<downloadUrl from the response>"
```

**n8n:** paste this workflow on the canvas (Ctrl+V). Then add one Header Auth credential with the name `Authorization` and the value `Bearer <your Apify token>`, and use it in both HTTP nodes.

- The second node downloads the merged PDF as an n8n binary, ready for Gmail, Drive or S3 nodes.
- To merge binaries that are already in n8n, send them in `files[].base64` instead of `url`.

```json
{
  "name": "PDF Merge API: merge PDFs from URLs",
  "nodes": [
    {"parameters": {}, "name": "When clicking Test workflow", "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [0, 0]},
    {"parameters": {"method": "POST", "url": "https://api.apify.com/v2/acts/ferrolark~pdf-merge-api/run-sync-get-dataset-items?maxTotalChargeUsd=0.01", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendBody": true, "specifyBody": "json", "jsonBody": "{\"files\": [{\"url\": \"https://www.irs.gov/pub/irs-pdf/fw9.pdf\", \"pages\": \"1\"}, {\"url\": \"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf\"}], \"outputFileName\": \"merged.pdf\"}", "options": {"timeout": 120000}}, "name": "Merge PDFs", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [220, 0]},
    {"parameters": {"url": "={{ $json.downloadUrl }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": {"response": {"response": {"responseFormat": "file"}}}}, "name": "Download merged PDF", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [440, 0]}
  ],
  "connections": {
    "When clicking Test workflow": {"main": [[{"node": "Merge PDFs", "type": "main", "index": 0}]]},
    "Merge PDFs": {"main": [[{"node": "Download merged PDF", "type": "main", "index": 0}]]}
  }
}
```

**Make / Zapier:**

1. Use the Apify app's "Run Actor" action with `ferrolark/pdf-merge-api`.
2. Fetch the dataset item.
3. Download `downloadUrl` with an HTTP module that sends the same `Authorization` header.

**AI agents (MCP):** add `ferrolark/pdf-merge-api` to the Apify MCP server (`https://mcp.apify.com?actors=ferrolark/pdf-merge-api`). An agent can then merge invoices, reports or contracts it already has links to.

### Use cases

- Build monthly invoice or receipt bundles for accounting from links in a spreadsheet.
- Combine a cover page, generated report pages and appendices into one deliverable.
- Extract the signature page or the first pages of long documents (`"pages": "1-2"`).
- Let an AI agent hand back one PDF instead of five attachments.

### Troubleshooting

- **"not a PDF file (no %PDF- header)"**: the URL returned an HTML page, often a login wall or a viewer page. Use a direct download link.
- **"password-protected"**: pass `password` for that file, or the top-level `password`.
- **"returned HTTP 403"**: the host blocks automated downloads. Upload the file to your own storage and send a signed URL, or send it as base64.
- **"more than 100 pages"**: use page ranges or split the job into several runs.
- **Text looks different**: the content is copied unchanged, so check the source file. Some PDF viewers render embedded fonts differently.

### Limitations

- No OCR, compression, conversion of other formats to PDF, or PDF/A output.
- It does not remove passwords you don't have.
- Signatures are not preserved, because merging creates a new document.
- Interactive forms that use document-level scripts may not behave the same after merging.

### Changelog

- **1.0** (November 2026): first release. URLs and base64 input, page ranges, bookmarks, encrypted input, signature and form warnings, deterministic output and a SHA-256 manifest.

### More Ferrolark tools

- [Brand Name Availability Checker](https://apify.com/ferrolark/brand-name-checker): domains, GitHub, npm, PyPI and more in one report.
- [Domain Intelligence Report](https://apify.com/ferrolark/domain-intelligence-report): WHOIS, DNS, email security, SSL and hosting for any domain.
- [Launch Asset Pack](https://apify.com/ferrolark/launch-asset-pack): favicons, PWA icons, OG image and head tags from one logo.
- [Live Deploy QA](https://apify.com/ferrolark/live-deploy-qa): meta tags, canonical, robots, OG image and favicon of your deployed routes, with diffs between deploys.
- [Sitemap Delta](https://apify.com/ferrolark/sitemap-delta): new, removed and broken URLs in any sitemap since the last run.
- [RSS Delta](https://apify.com/ferrolark/rss-delta): only new RSS, Atom and JSON Feed items, de-duplicated.
- [PDF Split API](https://apify.com/ferrolark/pdf-split-api): split a PDF by page ranges or every N pages, or extract pages, with a ZIP and manifest.
- [Image Convert](https://apify.com/ferrolark/image-convert): PNG, JPG, WebP, AVIF and HEIC conversion (SVG input too) from URLs or base64.
- [Image Compress & Resize](https://apify.com/ferrolark/image-compress-resize): resize images and compress them to a target size in KB, WebP or AVIF.
- [PDF to Image](https://apify.com/ferrolark/pdf-to-image): PDF pages to PNG, JPG or WebP at the DPI you choose.
- [Image to PDF](https://apify.com/ferrolark/image-to-pdf): JPG, PNG, HEIC and WebP images to one PDF, JPEGs embedded without recompression.
- [PDF Compress](https://apify.com/ferrolark/pdf-compress): smaller PDFs, lossless or with image downsampling; charged only when smaller.
- [HTML to PDF & URL to PDF](https://apify.com/ferrolark/html-to-pdf): web pages or raw HTML to PDF with headless Chrome.
- [Markdown to PDF](https://apify.com/ferrolark/markdown-to-pdf): Markdown with tables, code and footnotes to a clean PDF.
- [DOCX to PDF](https://apify.com/ferrolark/docx-to-pdf): Word, Excel, PowerPoint and ODT to PDF with LibreOffice.
- [Data Convert](https://apify.com/ferrolark/data-convert): CSV, JSON, NDJSON and Excel XLSX in any direction.

***

*Built by Ferrolark.*

# Actor input Schema

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

PDF files to merge, in order. Public http(s) URLs, including signed links from S3, Google Cloud Storage or an Apify key-value store.

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

Advanced: a list of objects merged after pdfUrls. Each one has "url" or "base64" (the file itself, for n8n/Make binaries), plus optional "pages" (for example "1-3,5,8-" or "last"), "name" (bookmark title) and "password".

## `outputFileName` (type: `string`):

Name of the merged PDF in the run's key-value store.

## `addBookmarks` (type: `boolean`):

Adds an outline entry pointing to the first page of each input file.

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

Optional document title written to the PDF metadata.

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

Used to open password-protected inputs that do not have their own "password" in files. The output is not encrypted.

## `createShareableUrl` (type: `boolean`):

Also return a signed URL that works without an Apify token. Anyone with the link can download the file until the run's storage is deleted. Off by default.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
    "https://pdfobject.com/pdf/sample.pdf"
  ],
  "files": [],
  "outputFileName": "merged.pdf",
  "addBookmarks": true,
  "createShareableUrl": false
}
```

# 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 = {
    "pdfUrls": [
        "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
        "https://pdfobject.com/pdf/sample.pdf"
    ],
    "files": []
};

// Run the Actor and wait for it to finish
const run = await client.actor("ferrolark/pdf-merge-api").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 = {
    "pdfUrls": [
        "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
        "https://pdfobject.com/pdf/sample.pdf",
    ],
    "files": [],
}

# Run the Actor and wait for it to finish
run = client.actor("ferrolark/pdf-merge-api").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 '{
  "pdfUrls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
    "https://pdfobject.com/pdf/sample.pdf"
  ],
  "files": []
}' |
apify call ferrolark/pdf-merge-api --silent --output-dataset

```

## MCP server setup

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

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/Wpx6wWnu9fK9LE0NV/builds/Fi3lPYdQ5gJ1zcuA0/openapi.json
