# PDF Redactor – True PII Redaction (Emails, Phones, IBAN, Cards) (`freecamp008/pdf-redactor`) Actor

Redact PDFs for real: automatic PII detection (emails, phone numbers, IBAN, credit cards with Luhn check, SSN and national IDs, dates) plus your own terms and regex. Redacted text is permanently removed, not just covered, and verified by re-extraction. OCR for scanned pages. No external APIs.

- **URL**: https://apify.com/freecamp008/pdf-redactor.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 pdf redacteds

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 Redactor – Permanently Redact PII from PDFs (Emails, Phones, IBAN, Credit Cards, SSN)

**PDF Redactor** finds personal data in PDFs and removes it **for real**. Many "redaction" tools just draw a black rectangle over the text, and the hidden text can still be copied or extracted. This Actor rebuilds every affected page without the redacted content, then **re-extracts the output and verifies** that none of the redacted text survives. It detects **emails, phone numbers, IBANs, credit card numbers (Luhn-checked), SSNs and national IDs, dates, IP addresses and URLs**, plus your own **words, names and regular expressions**, and can **OCR scanned pages**. Everything runs inside the Actor: no external APIs, and your documents never leave Apify.

### What does PDF Redactor do?

- 🕵️ **Built-in PII detection** with validation to avoid false positives: IBAN mod-97 checksum, credit card Luhn + issuer prefixes, phone numbers validated with Google's libphonenumber (plus any number after *Tel / Phone / Fax / Mobile* labels), US SSN rules, UK NINO, IDs after keywords such as *SSN, TIN, passport, tax ID, Steuer-ID, DNI, PESEL*.
- ✍️ **Custom rules**: literal terms (names, companies, addresses, case numbers; case-insensitive, whole-word, robust to line breaks) and JavaScript regular expressions.
- 🔥 **True removal**: pages with redactions are re-rendered as images with opaque boxes; the original text, fonts and drawing operators of those pages are gone. Hidden text (white text, text under images, off-page text), comments, form-field values and links (`mailto:`) on those pages are removed too.
- 🔎 **Still searchable**: the non-redacted words are written back as an invisible text layer (optional), so the rest of the page can still be searched and copied. Redacted words are never written back.
- ✅ **Verified output**: the finished PDF is parsed again; every detector is re-run and every redacted string is searched for. If anything is found, the affected pages are rebuilt without a text layer; if it still fails, no file is produced and nothing is charged.
- 📄 **Untouched pages stay original**: pages without findings are copied unchanged (vector quality, small files), unless you choose *Rebuild every page*.
- 🧾 **Redaction report**: page, bounding box (PDF points, top-left origin), category, rule and a masked preview (`j**e.d*e@e*****e.com`) for every redaction. The report contains no personal data unless you ask for it.
- 🧹 **Clean metadata**: the output is a new document without the original title, author, XMP metadata, bookmarks, attachments or JavaScript.
- 🖨️ **Scanned pages**: optional OCR finds personal data on image-only pages.
- 🔐 Encrypted PDFs (password), detection-only mode, and an **HTTP API (Standby mode)**.

### Use cases

- **GDPR / CCPA / HIPAA** compliance before sharing documents with third parties
- **Freedom-of-information (FOIA) and e-discovery** releases
- **Anonymizing documents for AI**: remove personal data before sending PDFs to LLMs, RAG indexes or annotation teams
- Sharing **invoices, contracts, bank statements and HR files** without exposing contact details, bank accounts or IDs
- **Auditing**: run in detection-only mode to find out which documents contain personal data

### How to use it

1. Click **Try for free** and paste one or more **PDF URLs**.
2. Choose which **personal data** to detect and add your own **terms** or **regular expressions** (optional).
3. Enable **OCR scanned pages** if your PDFs contain scans.
4. Click **Start**. Each PDF becomes one row with the redacted file (`outputUrl`), counts by category, the verification result and the list of redactions.

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

```bash
## GET with query parameters
curl "https://<your-standby-url>/?pdfUrls=https://example.com/contract.pdf&piiTypes=email,phone,iban" \
  -H "Authorization: Bearer <APIFY_TOKEN>"

## POST with a JSON body, redacted PDF inline as base64
curl -X POST "https://<your-standby-url>/" \
  -H "Authorization: Bearer <APIFY_TOKEN>" -H "Content-Type: application/json" \
  -d '{"pdfUrls":["https://example.com/contract.pdf"],"terms":["Jane Doe"],"regexes":["CASE-\\d{6}"],"returnBase64":true}'
```

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

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
{
  "pdfUrls": ["https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/QualityHosting.pdf"],
  "piiTypes": ["email", "phone", "iban", "credit_card", "national_id"],
  "terms": ["Jane Doe", "Project Falcon"],
  "regexes": ["INV-\\d{6}"],
  "ocrScannedPages": false,
  "keepTextSearchable": true,
  "dpi": 200
}
```

| Field | Description |
|---|---|
| `pdfUrls` | PDFs to redact (also `data:application/pdf;base64,...`) |
| `piiTypes` | `email`, `phone`, `iban`, `credit_card`, `national_id`, `date`, `ip_address`, `url` |
| `terms` / `regexes` | Your own literal terms and JavaScript regular expressions (`/pattern/flags` or plain) |
| `caseSensitive` / `wholeWords` | Matching options for terms (default: case-insensitive, whole words) |
| `phoneCountry` | Two-letter code (e.g. `US`, `DE`) to also detect national numbers without `+` |
| `ocrScannedPages` / `ocrLanguage` | OCR pages without a text layer (charged per page) |
| `keepTextSearchable` | Write the non-redacted words back as invisible text (default on) |
| `rasterizeAllPages` | Rebuild every page, not only pages with findings |
| `dpi` | Resolution of rebuilt pages (100-400, default 200) |
| `boxColor` | Redaction box colour (default `#000000`) |
| `includeMatchedText` | Put the original matched text in the report (default off) |
| `outputPdf` | Turn off for detection-only runs |
| `maxPages` | Larger PDFs are rejected (no partial redaction) |
| `password` | Password for encrypted PDFs |
| `returnBase64` | Standby API only: include the redacted PDF as base64 |

### Output example

```json
{
  "pdfUrl": "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/QualityHosting.pdf",
  "outputUrl": "https://api.apify.com/v2/key-value-stores/<storeId>/records/QualityHosting-2e4c9135c0db-redacted",
  "pageCount": 2,
  "redactionCount": 9,
  "categories": { "phone": 4, "email": 3, "iban": 2 },
  "redactedPages": [1, 2],
  "rebuiltPages": [1, 2],
  "ocrPages": [],
  "verification": { "passed": true, "checkedPages": 2, "bannedStrings": 5, "leaks": [] },
  "redactions": [
    { "page": 1, "category": "phone", "bbox": { "left": 68.8, "top": 792.4, "width": 64.1, "height": 9 }, "source": "text", "preview": "+** 6**1 9*6 ** **" },
    { "page": 1, "category": "email", "bbox": { "left": 76, "top": 816.5, "width": 72.4, "height": 9 }, "source": "text", "preview": "i**o@q************g.**" },
    { "page": 1, "category": "iban", "bbox": { "left": 415.4, "top": 800.3, "width": 88.9, "height": 9 }, "source": "text", "preview": "D********************7" }
  ],
  "outputBytes": 528697,
  "processingMs": 712
}
```

`source` is `text`, `ocr` or `annotation:<type>` (form field, comment, link). Annotation findings that are not visible on the page have `bbox: null`: they are removed together with the rebuilt page.

### Pricing

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

| Event | Price |
|---|---|
| PDF redacted (any number of pages, verification included) | **$10 per 1,000 PDFs** ($0.01 each) |
| OCR page (only with *OCR scanned pages*) | **$3 per 1,000 pages** ($0.003 each) |

Failed downloads, broken PDFs and outputs that fail verification are free. Apify platform usage (compute) is billed separately. Set **Maximum cost per run** to cap your spend. A PDF is either fully processed or not at all: if the OCR it needs doesn't fit into the remaining budget, it is skipped rather than partially redacted.

### FAQ

**Is the redaction really permanent?**
Yes. Pages with findings are replaced by freshly rendered images with opaque boxes; the original text objects of those pages are not copied into the output. The output is then re-parsed and checked for every redacted string and every PII pattern. Pages without findings are copied unchanged; enable *Rebuild every page* if you also want to strip hidden layers and comments from those.

**Why is the redacted page an image?**
Rebuilding the page as an image is the only method that is guaranteed to work on every PDF (any font encoding, Type 3 fonts, text drawn in pieces, overlapping objects). With *Keep remaining text searchable* the page still behaves like a text page for search and copy, minus the redacted words. File size grows by roughly 100-500 KB per rebuilt page at 200 DPI.

**How accurate is the detection?**
Validated detectors (IBAN checksum, Luhn, libphonenumber) give very few false positives. Phone numbers without a `+` are only detected after a label (Tel, Phone, Fax...) unless you set `phoneCountry`. Names are not detected automatically: add them as terms. Always review the report for sensitive releases.

**Does it work with scanned PDFs?**
Yes, with *OCR scanned pages* (Tesseract, 100+ languages). Without it, image-only pages are listed in `scannedPagesNotChecked` with a warning. Handwriting is not reliably recognized.

**What is not covered?**
Text drawn as vector outlines (no text layer, but not a scan either) and text inside images on pages that do have a text layer are not analyzed. Rotated text is found and boxed, but not written back to the searchable layer. Pure XFA forms are rendered as their placeholder page.

**Which languages are supported?**
Pattern detectors are language-independent; keyword-based detectors understand English, German, French, Spanish, Italian, Dutch and Polish labels. Terms work in any language and script. OCR supports all Tesseract languages.

**Is it legal? Is my data private?**
Redacting personal data is how organisations comply with GDPR, CCPA and FOIA obligations; you remain responsible for checking that the result meets your legal requirements. Files are processed inside your Apify run and stored only in your run's key-value store; nothing is sent to third-party services, and the report masks the redacted values by default.

**Licenses?**
pdf.js (Apache-2.0), @cantoo/pdf-lib (MIT), libphonenumber-js (MIT), tesseract.js and tessdata (Apache-2.0), @napi-rs/canvas (MIT). All allow commercial use.

# Actor input Schema

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

Direct links to the PDFs to redact (or <code>data:application/pdf;base64,...</code> URLs). Each PDF becomes one redacted PDF plus a list of redactions.

## `piiTypes` (type: `array`):

Built-in detectors. <b>email</b>, <b>phone</b> (international numbers validated with libphonenumber, plus any number after Tel/Phone/Fax/Mobile), <b>iban</b> (checksum-validated), <b>credit_card</b> (Luhn-validated), <b>national_id</b> (US SSN, UK NINO, and IDs after keywords like SSN, TIN, passport, tax ID), <b>date</b>, <b>ip_address</b>, <b>url</b>.

## `terms` (type: `array`):

Literal terms such as names, company names, addresses or case numbers. Matching ignores case and line breaks inside phrases.

## `regexes` (type: `array`):

JavaScript regular expressions for custom patterns, e.g. <code>INV-\d{6}</code> or <code>/Kundennummer:\s\*\d+/i</code>.

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

Match terms (and regexes without flags) case-sensitively.

## `wholeWords` (type: `boolean`):

Terms only match complete words ("Ann" does not match "Annual").

## `phoneCountry` (type: `string`):

Optional two-letter country code (e.g. <code>US</code>, <code>DE</code>, <code>FR</code>) so national phone numbers without a + prefix are detected too. Leave empty to detect international numbers and numbers after Tel/Phone/Fax labels only.

## `ocrScannedPages` (type: `boolean`):

Also find personal data on pages without a text layer (scans, photos) using built-in OCR. Charged per OCR'd page.

## `ocrLanguage` (type: `string`):

Tesseract language code(s) for scanned pages, e.g. <code>eng</code>, <code>deu</code>, <code>eng+fra</code>.

## `keepTextSearchable` (type: `boolean`):

Redacted pages are rebuilt as images (that is what makes the removal permanent). With this on, the non-redacted words are put back as an invisible text layer so the page stays searchable and copyable. Redacted words are never written back.

## `rasterizeAllPages` (type: `boolean`):

Rebuild all pages as images, not only pages with redactions. Strongest option: also strips hidden layers, comments and invisible content from pages without matches.

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

Resolution used to rebuild redacted pages. 200 is crisp for text; 300 for small print; 150 for smaller files.

## `boxColor` (type: `string`):

Hex colour of the redaction boxes.

## `includeMatchedText` (type: `boolean`):

Add the original matched text to every redaction in the results. Off by default so the report itself contains no personal data (a masked preview like <code>j**n@e**\*\*\*e.com</code> is always included).

## `outputPdf` (type: `boolean`):

Turn off for a detection-only run that just lists what would be redacted (faster, no file produced).

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

PDFs with more pages are rejected (a partially redacted document would be unsafe).

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

Password for encrypted PDFs (optional). The redacted PDF is saved without encryption.

## `returnBase64` (type: `boolean`):

Standby HTTP API only: also include the redacted PDF as a base64 string (<code>pdfBase64</code>) in the response.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/QualityHosting.pdf"
  ],
  "piiTypes": [
    "email",
    "phone",
    "iban",
    "credit_card",
    "national_id"
  ],
  "terms": [
    "Jane Doe",
    "Project Falcon"
  ],
  "regexes": [
    "INV-\\d{6}"
  ],
  "caseSensitive": false,
  "wholeWords": true,
  "ocrScannedPages": false,
  "ocrLanguage": "eng",
  "keepTextSearchable": true,
  "rasterizeAllPages": false,
  "dpi": 200,
  "boxColor": "#000000",
  "includeMatchedText": false,
  "outputPdf": true,
  "maxPages": 500,
  "returnBase64": 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://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/QualityHosting.pdf"
    ],
    "piiTypes": [
        "email",
        "phone",
        "iban",
        "credit_card",
        "national_id"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("freecamp008/pdf-redactor").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://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/QualityHosting.pdf"],
    "piiTypes": [
        "email",
        "phone",
        "iban",
        "credit_card",
        "national_id",
    ],
}

# Run the Actor and wait for it to finish
run = client.actor("freecamp008/pdf-redactor").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://raw.githubusercontent.com/invoice-x/invoice2data/master/tests/compare/QualityHosting.pdf"
  ],
  "piiTypes": [
    "email",
    "phone",
    "iban",
    "credit_card",
    "national_id"
  ]
}' |
apify call freecamp008/pdf-redactor --silent --output-dataset

```

## MCP server setup

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

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/hQBhUm3ay7FeUgIAi/builds/xN3W4AKXzgivOgTXz/openapi.json
