# Redact a PDF Without Leaving the Text Behind

> Canonical: https://skillalmanac.com/learn/redact-a-pdf-without-leaking-text | Updated: 2026-11-27 | Index status: index-eligible

A drawn black box does not remove PDF text. Mark the areas, apply redactions, save with garbage collection, then extract the text again to check.

## Facts

- 2026-11-26: Page.add_redact_annot is the first of two steps and only marks the area; removal happens in Page.apply_redactions, which then deletes the redaction annotations (https://pymupdf.readthedocs.io/en/latest/page.html)
- 2026-11-26: By default apply_redactions removes all characters whose boundary box overlaps any redaction rectangle, and removal is done by character (https://pymupdf.readthedocs.io/en/latest/page.html)
- 2026-11-26: Setting text to PDF_REDACT_TEXT_NONE (1) keeps text, and the docs say this does not comply with the data protection intentions of redaction annotations (https://pymupdf.readthedocs.io/en/latest/page.html)
- 2026-11-26: The default images setting blanks out overlapping pixels by creating a new image and does not delete the original image; the remove option removes only this page's references to the image (https://pymupdf.readthedocs.io/en/latest/page.html)
- 2026-11-26: The graphics parameter removes overlapping vector graphics by default, and option 0 ignores graphics (https://pymupdf.readthedocs.io/en/latest/page.html)
- 2026-11-26: Document.save takes a garbage option from 0 (none) to 4; 1 removes unused (unreferenced) objects, and positive values exclude incremental saves (https://pymupdf.readthedocs.io/en/latest/document.html)
- 2026-11-26: Page.search_for returns a list of rectangles and can return more than one rectangle for a string that spans lines (https://pymupdf.readthedocs.io/en/latest/page.html)
- 2026-11-27: Document.scrub is a separate PDF-only method described as removing potentially sensitive data, with options for attached files, embedded files, hidden text, JavaScript, metadata, links, form fields, annotation responses, thumbnails and XML metadata (https://pymupdf.readthedocs.io/en/latest/document.html)
- 2026-11-26: pdftotext sends the text to stdout when the text-file argument is a hyphen (https://www.xpdfreader.com/pdftotext-man.html)

Drawing a black box over text does not remove that text from a PDF. The characters stay in the file, and a text extractor still returns them. Redaction removes the content inside each marked area, and you confirm the result by extracting the text again from the saved file.

Scope: the steps below remove matched content from the pages. They do not sanitize the whole file. Metadata, attachments, annotations and form values are separate parts of a PDF and need their own review, covered under Pitfalls.

## Steps with PyMuPDF

The steps below use the PyMuPDF library because its redaction behavior is documented on an official page, read on 2026-11-26. Other tools follow the same idea, but check their documentation for the exact commands.

1. Open the PDF and find the rectangle around each item you need to remove. `page.search_for("some text")` returns a list of rectangles. A string that breaks across two lines comes back as two rectangles, so mark every rectangle in the list.
2. For each rectangle, call `page.add_redact_annot(rect)`. The docs call this the first of two steps. It only marks the area. Nothing is removed yet.
3. After you mark every rectangle on a page, call `page.apply_redactions()` on that page. By default it removes every character whose bounding box overlaps a marked rectangle, and it then deletes the redaction annotations themselves.
4. Set the `images` argument on purpose. The default blanks out the overlapping image pixels, and option 0 ignores images. Leave images untouched only when you have checked that they hold nothing sensitive.
5. Set the `graphics` argument on purpose. The default removes overlapping vector graphics. Option 0 ignores graphics, so line art that carries sensitive information can survive.
6. Save to a new file, not over the original, and pass a `garbage` value above 0 to `doc.save()`. The docs say removed text is physically gone from the page "assuming `Document.save()` with a suitable garbage option". For images, the default setting writes a new blanked image for the page and does not delete the original, so the original can stay in the file as an unused object until garbage collection removes it. `garbage=1` removes unused objects and `garbage=4` is the highest level.

This script was run on 2026-11-26 with PyMuPDF 2.0 (MuPDF 1.28.5) on a one-page test file that contained the string `078-05-1120`:

```python
import pymupdf

doc = pymupdf.open("original.pdf")
for page in doc:
    for rect in page.search_for("078-05-1120"):
        page.add_redact_annot(rect)
    page.apply_redactions()
doc.save("redacted.pdf", garbage=4, deflate=True)
```

## Check that it worked

Extract the text of the saved file with a different tool from the one that redacted it, and search for every string you meant to remove. With the Xpdf `pdftotext` tool, a hyphen as the output name sends the text to the terminal:

```
pdftotext redacted.pdf -
```

In the test run, a copy of the file with only a black rectangle drawn over the number still returned `078-05-1120` from this command, and so did a copy that was marked but never applied. The redacted file returned the rest of the line without the number.

The extraction check and the rendered pages are evidence for the areas you marked. They are not proof that nothing recoverable remains elsewhere in the file.

Then render the redacted pages as images and look at them. A string that still appears in the extracted text means no redaction rectangle overlapped those characters. Mark a larger area, rerun from the original file, and check again.

## Pitfalls

- **Box only, no apply step.** A filled shape drawn over the text leaves the text in place. So does a redaction annotation that was added but never applied. The extraction check above catches both.
- **Rectangle covers only part of a word.** Removal is done character by character: a character goes only if its bounding box overlaps a redaction rectangle. In the test run, a rectangle over the left half of `078-05-1120` left `-1120` in the extracted text. The docs also warn that, depending on the font and line height, the overlap rule can remove text you did not mean to remove, so check the neighbouring lines too.
- **Keeping text.** Setting `text=1` (`PDF_REDACT_TEXT_NONE`) keeps the text inside the area. The PyMuPDF docs say this does not comply with the data protection intentions of redaction, so do not use it to hide personal data.
- **Images.** On a scanned page the data sits in image pixels, so text extraction cannot confirm that it is gone. Render the page and look. The default `images` setting creates a new blanked image for this page only; the docs note that the original image is not deleted or replaced, so other pages may still show it. The remove option (`images=1`) removes only this page's references to the image, and the image leaves the file only when nothing references it any more and the save uses garbage collection. In the test run, a file saved with `garbage=0` after a default image redaction held two image objects, and the same file saved with `garbage=4` held one.
- **Document properties.** `apply_redactions` works on the content of a page. In the test run the author, creator, and producer values were unchanged after redaction. Check those fields separately before sending the file.
- **Content outside the page.** In a second run on 2026-11-27 with PyMuPDF 2.0, a synthetic PDF held the same harmless marker string in its page text, in its metadata and in an embedded text attachment. After the redaction script above and a `garbage=4` save, page extraction no longer returned the marker, but the metadata and the attachment still contained it. Before sending a file, also review attached and embedded files, annotations and their replies, form field values, links, JavaScript, thumbnails and XML metadata. PyMuPDF documents a separate `Document.scrub()` method whose options name these parts. It was not run for this guide, so if you use it, inspect its output the same way.

## When to use a skill instead

A single PDF with a short list of known strings is quicker to redact by hand than to build a script around. A reusable skill may be worth trying when the same kinds of data appear across many files.

[sensitive-data-redaction](/skills/skill-almanac/sensitive-data-redaction) replaces emails, phone numbers, card and bank numbers, keys, IP addresses, and named people in a ticket, log, export, or document, and reports what it replaced. It fits when the PDF text has already been pulled into a text file that will go to an AI tool or another person. Its page lists efficacy as LIFT from a single run on 3 tasks (2026-11-21) and marks that result as provisional, so read it as an early signal, not a full measurement.

[pdf-metadata-privacy-check](/skills/skill-almanac/pdf-metadata-privacy-check) reads the document information entries, such as Author, Creator, and Producer, plus four XMP fields, and flags a name-like pattern in the Author field, email addresses, and Windows or Unix home paths. It reports only and never changes the file. No comparison with and without this skill has been run, so its effect is not measured.

## FAQ

### Does redacting the pages clean the whole PDF?

No. Applying redactions removes content on the pages. Metadata, attachments, annotations and form values are stored separately. In the test file, the metadata and an embedded attachment still held the removed string after the pages were redacted. Review all of these parts before you send the file.

### Is putting black over text the same as redacting it?

No. A drawn box leaves the characters in the file, and text extraction can still read them. Redaction removes the characters that overlap the marked area.

### Does redaction also remove images?

It depends on the `images` setting. The default blanks out only the overlapping pixels in a new copy of the image, option 0 ignores images, and the remove option removes this page's references to the image. Save with a `garbage` value above 0 so that the unused original can be dropped from the file.

### Can I keep the text when I redact?

The option exists, but the PyMuPDF docs say keeping text does not comply with the data protection intentions of redaction. Use the default removal when the goal is to hide sensitive data.

## Related skills

- [sensitive-data-redaction](https://skillalmanac.com/skills/skill-almanac/sensitive-data-redaction.md): Platform Score 55/100 (provisional)
- [pdf-metadata-privacy-check](https://skillalmanac.com/skills/skill-almanac/pdf-metadata-privacy-check.md): Platform Score 42/100 (provisional)

## Related guides

- [How to Use AI in Marketing Without Unsupported Claims](https://skillalmanac.com/learn/how-to-use-ai-in-marketing.md)
- [Format SQL with an AI agent without changing its meaning](https://skillalmanac.com/learn/format-sql-with-an-ai-agent.md)
- [Check a Resume for ATS Problems With an AI Agent](https://skillalmanac.com/learn/check-a-resume-for-ats-with-an-ai-agent.md)
- [How to Use AI in Excel: Formulas Versus Whole-Sheet Analysis](https://skillalmanac.com/learn/how-to-use-ai-in-excel.md)
- [How to Use AI to Design a Room: Photo to Brief](https://skillalmanac.com/learn/how-to-use-ai-to-design-a-room.md)
- [Rewrite a Paragraph with an AI Agent and Keep Its Facts](https://skillalmanac.com/learn/rewrite-a-paragraph-with-an-ai-agent.md)

## Sources

- https://pymupdf.readthedocs.io/en/latest/page.html
- https://pymupdf.readthedocs.io/en/latest/document.html
- https://www.xpdfreader.com/pdftotext-man.html

Platform Scores report our assessment under a published method. They are not a safety guarantee.
