PDF extraction

How to Redact a PDF (So the Text Is Actually Gone)

Most PDF redaction leaves the original text recoverable. Here's how real redaction works, how to do it, and how to verify the words are truly removed.

July 21, 2026 7 min read okraPDF

There is a specific, embarrassing way that PDF redaction fails, and it happens over and over: someone opens a document, draws black rectangles over the sensitive parts, saves it, and ships it — and the “hidden” text is still sitting in the file, one copy-paste away from anyone who wants it. Courts, agencies, and companies have all published “redacted” documents whose blacked-out names came right back with a select-all. If you are building a document workflow, this is the failure mode you have to design against.

This guide is about doing it correctly: what real redaction actually removes, the steps to do it, and — the part almost everyone skips — how to verify that the text is gone.

Why the black box doesn’t work

A PDF is not an image. It is a set of drawing instructions. Text lives in a content stream as encoded strings with positioning operators; the glyphs you see are rendered from those strings at display time. Annotations, form fields, and vector shapes are separate objects layered on top.

When you draw a black rectangle over a name, you are adding one more object to the page — an opaque rectangle at some coordinates. You have changed what the page looks like. You have not touched the text object underneath. The characters are still in the content stream, in reading order, fully selectable. Any of these recovers them:

  • Select-all and copy. The rectangle is above the text visually, but the text is still the text.
  • Text extraction. pdftotext, pdfplumber, or any parser reads the content stream directly and never sees your rectangle.
  • Moving or deleting the annotation in an editor that treats the box as a separate object.

The same trap catches a few adjacent techniques. Changing the text color to white leaves the string intact. Placing a highlight annotation over it does nothing to the underlying glyphs. Even “flattening” that only merges annotations into the page can leave the original text stream in place if it flattens the box on top rather than removing what’s below.

What true redaction removes

Real redaction is destruction, not concealment. Three things have to happen:

  1. The text content is removed from the content stream. Not covered — deleted. The bytes for “Jane Q. Public, SSN 123-45-6789” are gone from the page’s drawing instructions and replaced (typically) by a solid mark that carries no recoverable data.
  2. Associated objects are cleaned. If the redacted region was inside a form field, a link annotation, a comment, or a tagged-content structure element, those references get scrubbed too. A phone number can hide in a form field’s value or a link’s URI even after the visible text is gone.
  3. Hidden and out-of-band data is scrubbed. This is the step people forget. A PDF carries a lot besides page text.

That third bucket is worth spelling out, because “the page looks clean” says nothing about it:

  • Document metadata — the Info dictionary and XMP packet (author, title, subject, keywords, producer). A “redacted” filing whose XMP title is Smith v. Acme — settlement $2.4M has redacted nothing.
  • Embedded files and attachments — a spreadsheet stapled to the PDF travels with it.
  • Comments and annotations — review notes, sticky notes, and markups elsewhere in the document.
  • Optional content groups (layers) — content on a hidden layer is still in the file.
  • Form field values — an AcroForm field can hold the original string even when the widget looks blank.
  • Prior revisions — incremental saves can leave earlier versions of the page appended in the file. A redaction that only adds a new revision can leave the un-redacted page recoverable earlier in the byte stream.

If your threat model is “someone will open this in Acrobat,” covering text feels like enough. If your threat model is “someone technical will run a parser or a hex editor” — which is the correct assumption for anything public — only removal counts.

How to redact a PDF properly

Whether you do this by hand or in code, the sequence is the same.

1. Decide what qualifies as sensitive

Make the list explicit before you touch the file, because “redact the personal information” is not a spec. For most documents the PII set is names, government IDs (SSN, passport, driver’s license), account and card numbers, dates of birth, home addresses, phone numbers, email addresses, and handwritten signatures. Regulated documents add their own categories — protected health information, financial account details, and so on. Write the list down; you will use it again when you verify.

2. Remove the content, don’t cover it

Select each sensitive span and apply a redaction that removes the underlying text and draws a mark in its place. The distinction to look for in any tool: does it delete the text object, or does it stack a shape on top? If a tool lets you later move the black box and reveal the text, it never redacted anything.

3. Scrub metadata and hidden data

After the page content is clean, strip the Info dictionary and XMP, drop embedded files you don’t intend to ship, remove stray annotations and comments, flatten form fields, and remove hidden layers. On the command line, exiftool -all= file.pdf clears most metadata; qpdf --linearize (or a full re-save) can help collapse incremental revisions so an earlier un-redacted state isn’t left appended in the file.

4. Re-save as a clean document

Write out a fresh PDF so the result is a single, consolidated version with no earlier revisions hiding in the byte stream. The output should be the only copy of that page that exists in the file.

5. Verify before it leaves your hands

Never trust that redaction worked because the page looks right. Prove it. That is the next section, and it is not optional.

How to verify a redaction actually held

Verification is the step that separates real redaction from theater. Three cheap checks catch almost every failure.

The copy test. Open the finished PDF, select all (Cmd/Ctrl-A), copy, and paste into a plain-text editor. If any redacted string shows up, the redaction failed. This takes ten seconds and catches the classic black-box mistake immediately.

The extraction test. Machines don’t care about black boxes — they read the content stream. Run the redacted file through a text extractor and grep for the exact strings you removed:

pdftotext redacted.pdf - | grep -i "123-45-6789"
# no output = the number is not in the text stream

Or, in Python, check every page against your sensitive list:

import pdfplumber

SECRETS = ["123-45-6789", "Jane Q. Public", "jane@example.com"]

with pdfplumber.open("redacted.pdf") as pdf:
    text = "\n".join(page.extract_text() or "" for page in pdf.pages)

leaks = [s for s in SECRETS if s.lower() in text.lower()]
assert not leaks, f"Redaction leaked: {leaks}"
print("Clean — no redacted strings found in the text layer.")

The metadata test. Check the parts that don’t show on the page:

exiftool redacted.pdf          # Info + XMP fields
# and confirm there are no embedded files / attachments you didn't intend

If all three come back clean — nothing copyable, nothing extractable, nothing lurking in metadata — the redaction held. Bake these checks into your pipeline so a bad redaction fails loudly instead of shipping.

One honest caveat: text removal does not defeat every recovery path. If a page is a scanned image, the “text” is pixels, and blacking out pixels genuinely removes them — but if that image was ever OCR’d into a text layer, redact the text layer too. And a redaction that only blurs or pixelates small, low-entropy fields (a short PIN, a few-digit code) can sometimes be reversed; solid removal avoids that entirely.

Redact a PDF in your browser, free

If you want true redaction without wiring up a toolchain, use the free okraPDF redaction tool. Draw boxes over the sensitive spans and it removes the text from the file — it doesn’t just hide it. It runs entirely in your browser, so the file never uploads anywhere, and there’s no signup and no watermark. You can draw the boxes by hand or feed it coordinates if you’re scripting the regions.

For the broader picture — how to think about redaction across a whole document pipeline, including PII identification and metadata scrubbing at scale — see our companion guide on how to redact documents securely.

Redaction is one of those tasks where “looks done” and “is done” are completely different states. Remove the content, scrub the metadata, and always run the copy-and-extraction test before the document leaves your hands.