> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formepdf.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Redact PDF

> Redact sensitive content from PDFs — by coordinates, text patterns, regex, presets, or saved templates.

`POST /v1/redact`

Redact sensitive content in a PDF by coordinates, text pattern, regex, preset, or saved template. Matching content is removed from the file, not only covered with a black box.

> [!WARNING]
>
> Use Forme 0.34.0 or later (server image `formepdf/forme:0.34.0`) for redaction. Output from earlier versions can still contain the redacted content. If you redacted documents with an earlier version, regenerate them from the originals: see [Redaction](https://docs.formepdf.com/concepts/redaction.md).

```
Authorization: Bearer forme_sk_...
```

> [!NOTE]
>
> This page documents the [self-hosted server](https://docs.formepdf.com/self-hosting.md). For the hosted API at `https://api.formepdf.com`, see [Hosted API — Redact](https://docs.formepdf.com/hosted-api/redact.md).

***

## Request Body

| Field | Type | Required | Description |
| - | - | - | - |
| `pdf` | `string` | Yes | Base64-encoded PDF bytes |
| `redactions` | `array` | No | Coordinate-based redaction regions |
| `patterns` | `array` | No | Text search patterns (max 50) |
| `presets` | `array` | No | Built-in pattern presets |
| `template` | `string` | No | Slug of a saved [redaction template](https://docs.formepdf.com/hosted-api/redaction-templates.md). Hosted API only: the self-hosted server returns `400`. |

At least one of `redactions`, `patterns`, `presets`, or `template` is required. All can be combined in a single request — patterns from all sources are merged.

***

## Coordinate Redaction

Redact specific rectangular regions by page coordinates.

Region coordinates are in points on the page **as displayed**: `x` and `y` are measured from the top-left corner of the visible area (the CropBox), after the page's `/Rotate` is applied. These are the coordinates a PDF viewer shows, and the ones `findTextRegions` returns.

**RedactionRegion fields:**

| Field | Type | Required | Description |
| - | - | - | - |
| `page` | `number` | Yes | Page number (0-indexed) |
| `x` | `number` | Yes | Points from the left edge of the page as displayed |
| `y` | `number` | Yes | Points from the top edge of the page as displayed |
| `width` | `number` | Yes | Width in points |
| `height` | `number` | Yes | Height in points |
| `color` | `string` | No | Redaction box color (default: black) |

```bash theme={null}
curl -X POST http://localhost:3000/v1/redact \
  -H "Authorization: Bearer forme_sk_abc123..." \
  -H "Content-Type: application/json" \
  -d "{
    \"pdf\": \"$(base64 -w0 document.pdf)\",
    \"redactions\": [
      {\"page\": 0, \"x\": 100, \"y\": 200, \"width\": 150, \"height\": 20}
    ]
  }" \
  --output redacted.pdf
```

***

## Text Pattern Redaction

Find and redact text by literal string or regular expression.

**RedactionPattern fields:**

| Field | Type | Required | Description |
| - | - | - | - |
| `pattern` | `string` | Yes | Text to search for (literal string or regex) |
| `pattern_type` | `string` | Yes | `"Literal"` or `"Regex"` |
| `page` | `number` | No | Restrict to a specific page (0-indexed). Omit to search all pages. |
| `color` | `string` | No | Redaction box color (default: black) |

```bash curl theme={null}
curl -X POST http://localhost:3000/v1/redact \
  -H "Authorization: Bearer forme_sk_abc123..." \
  -H "Content-Type: application/json" \
  -d "{
    \"pdf\": \"$(base64 -w0 document.pdf)\",
    \"patterns\": [
      {\"pattern\": \"Jane Doe\", \"pattern_type\": \"Literal\"},
      {\"pattern\": \"\\\\d{3}-\\\\d{2}-\\\\d{4}\", \"pattern_type\": \"Regex\"}
    ]
  }" \
  --output redacted.pdf
```

```javascript Node.js theme={null}
import fs from 'fs';

const pdf = fs.readFileSync('document.pdf').toString('base64');

const res = await fetch('http://localhost:3000/v1/redact', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer forme_sk_abc123...',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    pdf,
    patterns: [
      { pattern: 'Jane Doe', pattern_type: 'Literal' },
      { pattern: '\\d{3}-\\d{2}-\\d{4}', pattern_type: 'Regex' },
    ],
  }),
});

const redacted = Buffer.from(await res.arrayBuffer());
fs.writeFileSync('redacted.pdf', redacted);
```

```python Python theme={null}
import requests
import base64

with open("document.pdf", "rb") as f:
    pdf_b64 = base64.b64encode(f.read()).decode()

res = requests.post(
    "http://localhost:3000/v1/redact",
    headers={
        "Authorization": "Bearer forme_sk_abc123...",
        "Content-Type": "application/json",
    },
    json={
        "pdf": pdf_b64,
        "patterns": [
            {"pattern": "Jane Doe", "pattern_type": "Literal"},
            {"pattern": r"\d{3}-\d{2}-\d{4}", "pattern_type": "Regex"},
        ],
    },
)

with open("redacted.pdf", "wb") as f:
    f.write(res.content)
```

```go Go theme={null}
pdf, _ := os.ReadFile("document.pdf")

body, _ := json.Marshal(map[string]any{
	"pdf": base64.StdEncoding.EncodeToString(pdf),
	"patterns": []map[string]string{
		{"pattern": "Jane Doe", "pattern_type": "Literal"},
		{"pattern": `\d{3}-\d{2}-\d{4}`, "pattern_type": "Regex"},
	},
})

req, _ := http.NewRequest("POST", "http://localhost:3000/v1/redact", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer forme_sk_abc123...")
req.Header.Set("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()

out, _ := os.Create("redacted.pdf")
io.Copy(out, res.Body)
```

***

## Presets

Built-in patterns for common sensitive data types. Pass an array of preset names:

| Preset | Matches |
| - | - |
| `ssn` | US Social Security Numbers (XXX-XX-XXXX) |
| `email` | Email addresses |
| `phone` | US phone numbers |
| `date-of-birth` | Date patterns (MM/DD/YYYY, YYYY-MM-DD, etc.) |
| `credit-card` | Credit card numbers |

```bash theme={null}
curl -X POST http://localhost:3000/v1/redact \
  -H "Authorization: Bearer forme_sk_abc123..." \
  -H "Content-Type: application/json" \
  -d "{
    \"pdf\": \"$(base64 -w0 patient-record.pdf)\",
    \"presets\": [\"ssn\", \"email\", \"phone\", \"date-of-birth\"]
  }" \
  --output redacted.pdf
```

***

## Redaction Templates

On the [hosted API](https://docs.formepdf.com/hosted-api/redact.md), reference a saved [redaction template](https://docs.formepdf.com/hosted-api/redaction-templates.md) by slug:

```json theme={null}
{
  "pdf": "<base64>",
  "template": "hipaa-patient-record"
}
```

Combine a template with additional inline patterns — all sources are merged:

```json theme={null}
{
  "pdf": "<base64>",
  "template": "hipaa-patient-record",
  "patterns": [{"pattern": "Jane Doe", "pattern_type": "Literal"}],
  "presets": ["credit-card"]
}
```

> [!NOTE]
>
> Redaction templates require the hosted API. Self-hosted users should pass `patterns` and `presets` directly.

***

## Response

`200 OK` with `Content-Type: application/pdf` — the redacted PDF.

***

## What Redaction Does

* **Page content**: Text and images under a redacted region are removed from the page. Lines, shapes, and clipping paths are cut at the region's edges.
* **Hidden copies**: Matching text is removed from annotations, links, bookmarks, and alternate text.
* **Document data**: XMP metadata, embedded files, and document JavaScript are removed. The document information is replaced (`/Producer` is "Forme").
* **New file**: The output is written as a new file that holds only the content the document still uses. Earlier revisions of the input are not carried over.
* **Visual overlay**: A black rectangle covers each redacted area.

If the input cannot be redacted safely, the request fails with `422` and code `REDACTION_REFUSED` instead of returning a PDF. See Known Limitations.

> [!TIP]
>
> To check the result, see [Verifying redaction](https://docs.formepdf.com/concepts/redaction.md#verifying-redaction). Selecting text in a viewer is not enough.

***

## Known Limitations

* **Whole text runs**: A text run is removed whole when any of its glyphs is under a region: at least a fifth of the glyph's box lies under the region in each direction, or the centre of the box does. A glyph that is more than 80% outside the region along one axis, with its centre outside, stays. If the match shares a run with other words (for example a label on the same line), those words are removed too.
* **Images**: An image under a region is removed whole, even where most of it lies outside the region. Text inside an image is not searchable; run OCR first.
* **Vector graphics**: Paths under a region are cut at the region's edges. Curves in a cut path are redrawn as fine straight segments (within 0.05 pt).
* **Text search needs a text mapping**: Search finds text in fonts with a standard encoding or a ToUnicode map. Text without one cannot be found by search — use coordinate redaction.
* **Refused input**: These return an error instead of a PDF:
  * encrypted PDFs;
  * form fields under a region or holding matching text;
  * text, images, or paths inside a form XObject under a region;
  * an area painted with a tiling pattern under a region;
  * text drawn with a Type3 font that may lie under a region (including a Type3 font whose glyph bounds are unknown, anywhere on a page with a region);
  * text used as a clipping path (rendering modes 4 to 7) under a region;
  * a page whose `/Rotate` is not a multiple of 90, or that sets `/UserUnit`, when it has a region;
  * a region with a coordinate that is not a finite number.
* **Maximum 50 patterns per request**: Keep the total number of patterns (including those expanded from presets and templates) under 50.

***

## Related

* [Redaction](https://docs.formepdf.com/concepts/redaction.md) — how Forme redaction works, compliance use cases
* [Redaction Templates](https://docs.formepdf.com/hosted-api/redaction-templates.md) — creating and managing saved templates on the hosted API


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.