# PDF Compare – Text & Visual Diff of Two PDFs (`freecamp008/pdf-compare`) Actor

Compare two versions of a PDF: word-level text diff per page (added, removed, changed) plus a visual pixel diff with highlighted diff images and changed regions. Handles inserted/deleted pages. No external APIs.

- **URL**: https://apify.com/freecamp008/pdf-compare.md
- **Developed by:** [Camp8 fr0](https://apify.com/freecamp008) (community)
- **Categories:** Developer tools, Automation, AI
- **Features:** Limited permissions, Single-tenant, Server interface
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $10.00 / 1,000 document pair compareds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

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 Compare – Find Differences Between Two PDFs (Text Diff + Visual Diff)

**PDF Compare** shows exactly what changed between two versions of a PDF. It runs a **word-level text diff on every page** (added, removed and changed words with context and positions) and a **visual pixel diff** that catches changes text tools miss: images, logos, signatures, stamps, colours, layout shifts and scanned pages. For every changed page you get a **highlighted diff image** and the **changed regions** as coordinates. Inserted and deleted pages are detected automatically. Everything runs inside the Actor: no external APIs, and your documents never leave Apify.

### What does PDF Compare do?

- 📝 **Word-level text diff per page**: `changed` (old → new), `added` and `removed` passages with surrounding context and bounding boxes on both versions.
- 🖼️ **Visual diff**: both versions are rendered and compared pixel by pixel with anti-aliasing detection (pixelmatch), so font smoothing noise is ignored.
- 🎯 **Highlighted diff images**: faded original page, **removed ink in red**, **added ink in green**, changed regions boxed in orange.
- 📐 **Changed regions** as rectangles in PDF points (top-left origin) for building your own overlays or review UIs.
- 📑 **Smart page alignment**: an inserted or deleted page doesn't make every following page "different". Pages are matched by content; replaced pages are compared with each other.
- 🧾 **Summary**: `identical`, changed / added / removed pages, total words added and removed.
- 🔐 Encrypted PDFs (password), batch mode with many pairs, and an **HTTP API (Standby mode)**.

### Use cases

- **Contract and legal redlining**: see every changed clause between two drafts
- **Invoice, quote and price list checks**: spot changed amounts, dates and line items
- **Regulatory and policy documents**: track what changed between versions
- **Publishing and print QA**: compare proofs, catch moved logos or broken layouts
- **Automated regression tests** for PDF generators (reports, invoices, tickets)
- **Monitoring**: combine with a scheduler to detect when a published PDF changes

### How to use it

1. Click **Try for free**.
2. Paste the **Original PDF URL** and the **Revised PDF URL** (or a list of **pairs**).
3. Keep text and visual comparison on (default) and click **Start**.
4. Open the **Comparisons** view: each pair is one row with the summary and a preview of the first changed page. The `pages` array has the per-page details, the diff images are in the key-value store.

#### Call it as an HTTP API (Standby mode)

```bash
## GET with query parameters
curl "https://<your-standby-url>/?originalPdfUrl=https://example.com/v1.pdf&revisedPdfUrl=https://example.com/v2.pdf" \
  -H "Authorization: Bearer <APIFY_TOKEN>"

## POST with a JSON body (same fields as the Actor input)
curl -X POST "https://<your-standby-url>/" \
  -H "Authorization: Bearer <APIFY_TOKEN>" -H "Content-Type: application/json" \
  -d '{"originalPdfUrl":"https://example.com/v1.pdf","revisedPdfUrl":"https://example.com/v2.pdf","compareVisual":true,"dpi":150}'
```

Response: `{ "count": 1, "items": [ ...comparison... ] }`

You can also use the Apify API (`run-sync-get-dataset-items`), the Apify MCP server, Make, Zapier, n8n and other integrations. **AI agents can pay per call with x402 (USDC)** through Apify's agentic payments, without needing an Apify account.

### Input example

```json
{
  "originalPdfUrl": "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/coolblue1.pdf",
  "revisedPdfUrl": "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/coolblue2.pdf",
  "compareText": true,
  "compareVisual": true,
  "diffImages": true,
  "dpi": 100
}
```

| Field | Description |
|---|---|
| `originalPdfUrl` / `revisedPdfUrl` | The two versions to compare |
| `pairs` | Batch: `[{"original": url, "revised": url}, ...]` |
| `compareText` | Word-level text diff (default on) |
| `compareVisual` | Pixel diff (default on) |
| `diffImages` | Save highlighted PNGs for visually changed pages (default on) |
| `dpi` | Render resolution for the pixel diff (50-300, default 100) |
| `pixelThreshold` | Colour tolerance 0-1 (default 0.1); raise to ignore small colour/compression changes |
| `caseSensitive` | Case-sensitive text diff (default on) |
| `maxPages` | Page limit per document (default 300) |
| `password` | Password for encrypted PDFs (used for both) |

### Output example

```json
{
  "originalUrl": "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/coolblue1.pdf",
  "revisedUrl": "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/coolblue2.pdf",
  "identical": false,
  "summary": "1 changed page(s): 1; 100 word(s) added, 67 removed",
  "originalPageCount": 1,
  "revisedPageCount": 1,
  "pagesCompared": 1,
  "changedPages": [1],
  "addedPages": [],
  "removedPages": [],
  "wordsAdded": 100,
  "wordsRemoved": 67,
  "firstDiffImageUrl": "https://api.apify.com/v2/key-value-stores/<storeId>/records/coolblue2-08a01b0f8490-diff-p0001",
  "pages": [
    {
      "originalPage": 1,
      "revisedPage": 1,
      "status": "changed",
      "textChanged": true,
      "visualChanged": true,
      "wordsAdded": 100,
      "wordsRemoved": 67,
      "diffPercent": 1.108,
      "changes": [
        { "type": "changed", "original": "www.tabletcenter.nl", "revised": "www.laptopshop.nl", "context": "3012 CN Rotterdam Nederland",
          "originalBox": { "left": 445, "top": 102.8, "width": 76.2, "height": 8 }, "revisedBox": { "left": 445, "top": 102.8, "width": 73.1, "height": 8 } },
        { "type": "changed", "original": "19 april", "revised": "29 maart", "context": "993548900 Factuurnummer: 6669263 Klantnummer:" }
      ],
      "changedRegions": [{ "left": 463.7, "top": 100.8, "width": 60.5, "height": 15.1 }],
      "diffImageUrl": "https://api.apify.com/v2/key-value-stores/<storeId>/records/coolblue2-08a01b0f8490-diff-p0001"
    }
  ]
}
```

Page `status` values: `unchanged`, `changed`, `added` (only in the revised PDF), `removed` (only in the original), `not-compared` (max cost reached).

### Pricing

This Actor uses **pay-per-event** pricing:

| Event | Price |
|---|---|
| Document pair compared (includes the first 20 page pairs) | **$10 per 1,000 comparisons** ($0.01 each) |
| Extra page pair beyond 20 | **$0.50 per 1,000 pages** ($0.0005 each) |

A 10-page contract costs $0.01, a 100-page report $0.05. Failed downloads and broken PDFs are free. Apify platform usage (compute) is billed separately. Set **Maximum cost per run** to cap your spend; if the budget runs out mid-document, the remaining pages are marked `not-compared`.

### FAQ

**Does it work with scanned PDFs?**
Yes, through the visual diff: scanned pages are compared pixel by pixel and changed regions are boxed. The text diff needs a text layer (run OCR first, e.g. with a searchable-PDF Actor, if you also want word-level changes).

**Why do I see changes when the text looks identical?**
The visual diff also reports layout shifts, re-flowed text, font or colour changes and re-rendered images. If your PDFs come from different generators, raise `pixelThreshold` (e.g. 0.3) or disable `compareVisual` and rely on the text diff.

**How are pages matched?**
By content: pages are aligned with a similarity-based sequence alignment, so an inserted page shows up as `added` and the following pages still line up. Pages replaced at the same spot are compared with each other.

**In which order are words compared?**
In geometric reading order (top to bottom, left to right). This keeps diffs stable even when two exports write the same text in a different internal order. In multi-column layouts lines of neighbouring columns are interleaved, which can make the `context` look unusual but doesn't create false changes.

**Which languages are supported?**
Any language with a text layer (Latin, Cyrillic, Greek, CJK, Arabic...). Words are split on whitespace, so for Chinese/Japanese text without spaces a "word" may be a whole phrase.

**How big can the documents be?**
Up to 150 MB and 2,000 pages each (default limit 300). Memory: 2 GB is enough for typical documents at 100 DPI; use 4 GB for 300 DPI or very large pages.

**Is my data private?**
Files are processed inside your Apify run; diff images are stored only in your run's key-value store. Nothing is sent to third-party services.

**Licenses?**
pdf.js (Apache-2.0), pixelmatch (ISC), jsdiff (BSD-3-Clause), @napi-rs/canvas (MIT). All allow commercial use.

# Actor input Schema

## `originalPdfUrl` (type: `string`):

Direct link to the original (older) PDF, or a <code>data:application/pdf;base64,...</code> URL.

## `revisedPdfUrl` (type: `string`):

Direct link to the revised (newer) PDF to compare against the original.

## `pairs` (type: `array`):

Optional: compare several document pairs in one run, e.g. <code>\[{"original": "https://.../v1.pdf", "revised": "https://.../v2.pdf"}]</code>. Each pair becomes one result.

## `compareText` (type: `boolean`):

Diff the text layer word by word on every page: added, removed and changed words with context and positions.

## `compareVisual` (type: `boolean`):

Render both versions and compare pixels: catches changes in images, signatures, stamps, layout, colours and scanned pages that a text diff cannot see.

## `diffImages` (type: `boolean`):

Store a PNG for every visually changed page: the faded original with removed ink in red, added ink in green and changed regions boxed in orange.

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

Render resolution for the pixel diff. 100 is fast and catches text-level changes; use 150-200 for small print.

## `pixelThreshold` (type: `number`):

0-1: how different two pixels must be to count as changed (pixelmatch threshold). Raise it (e.g. 0.3) to ignore slight colour/compression differences.

## `caseSensitive` (type: `boolean`):

Treat "Total" and "total" as different words.

## `maxPages` (type: `integer`):

Safety limit on pages compared per document.

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

Password for encrypted PDFs (used for both documents).

## Actor input object example

```json
{
  "originalPdfUrl": "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/coolblue1.pdf",
  "revisedPdfUrl": "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/coolblue2.pdf",
  "pairs": [
    {
      "original": "https://example.com/contract-v1.pdf",
      "revised": "https://example.com/contract-v2.pdf"
    }
  ],
  "compareText": true,
  "compareVisual": true,
  "diffImages": true,
  "dpi": 100,
  "pixelThreshold": 0.1,
  "caseSensitive": true,
  "maxPages": 300
}
```

# Actor output Schema

## `comparisons` (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 = {
    "originalPdfUrl": "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/coolblue1.pdf",
    "revisedPdfUrl": "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/coolblue2.pdf"
};

// Run the Actor and wait for it to finish
const run = await client.actor("freecamp008/pdf-compare").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 = {
    "originalPdfUrl": "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/coolblue1.pdf",
    "revisedPdfUrl": "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/coolblue2.pdf",
}

# Run the Actor and wait for it to finish
run = client.actor("freecamp008/pdf-compare").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 '{
  "originalPdfUrl": "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/coolblue1.pdf",
  "revisedPdfUrl": "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/coolblue2.pdf"
}' |
apify call freecamp008/pdf-compare --silent --output-dataset

```

## MCP server setup

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

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/TnBXLDBvtD45YJlv2/builds/i0AqXF57OJ7pmEoUF/openapi.json
