Guide

How to redact a PDFso the words are actually gone

A black rectangle hides text from your eyes and from nothing else. The words stay in the file, and getting them back takes one line of code.

6 min read

Covering text with a black box leaves the text in the file, fully recoverable. Real redaction has to remove the text objects — and you can verify which one you have in about two minutes.

The thing almost everyone does

Open the PDF, pick the rectangle tool, set the fill to black, drag it over the account number, save. It looks right. The page is black where the number was, and nothing on screen suggests otherwise.

The rectangle is a drawing instruction. So is the text underneath it. Adding the first does not remove the second — it just tells a renderer to paint over that area afterwards. Both instructions are still in the file, and anything that reads the file rather than looking at it gets both.

This is the most-repeated mistake in document handling, and it keeps happening because the feedback is perfect: the result looks exactly like a redacted document.

A demonstration

Below is a PDF built from scratch: four lines of text, then two opaque black rectangles drawn precisely over two of them. Saved, closed, reopened. The file is 1,557 bytes.

Reading the page’s drawing instructions back out returns this:

> CONFIDENTIAL RECORD
> Patient: Jane Q. Doe
> Account 4929-1234-5678-9010
> Cleared for release after review.

Account number recoverable: YES
Patient name recoverable:   YES
Text recovered from the "redacted" file

Why the file gives it up so easily

A PDF page is a list of operators. Text arrives as a string followed by a show-text operator; a filled rectangle arrives as coordinates followed by a fill operator. They are peers in the same list, and the only thing the rectangle does is come later, so it paints on top.

In the file above, the text operators end well before the fill operators begin — 505 bytes in against 747. That ordering is the entire redaction. Change nothing but the order and the boxes would sit behind the words.

The strings themselves are stored as hexadecimal rather than plain letters, which is why searching a PDF in a text editor often turns up nothing and gives false comfort. Hex is not encryption. Decoding it is one line in any language, and every PDF reader on earth already does it — that is how copy-and-paste works.

The approaches that only sometimes work

Flattening is not redaction. It merges layers and form fields into the page content; text that was drawn under a rectangle is still text afterwards.

Printing to a new PDF, or exporting through a virtual printer, often does remove covered text, because the page gets re-generated from what was rendered. Often is not always: some printer drivers preserve the text layer deliberately so the output stays searchable, which is a feature everywhere except here.

Converting to images and back does work, and it is the blunt version of the right idea — but applied to a whole document it destroys the text on every page, including the pages that had nothing to hide.

The pattern worth noticing is that none of these tell you which outcome you got. That is the actual problem: the failure is silent.

What actually removes the words

There are two honest options. Edit the content stream to delete the text objects covering the marked area, or replace the page with an image of itself that was rendered with those areas painted out. Both end with a file in which the words do not exist, rather than one in which they are hidden.

Docqify takes the second route, and only for pages that carry a redaction. A rasterised page loses its selectable text, so a one-line redaction in a forty-page contract costs one page — every other page is copied across untouched and keeps its text, its links and its searchability.

The reason to prefer the image on the marked page is that it cannot half-work. Editing operators out of a content stream is exact when it succeeds and silently partial when the text is split across operators in an awkward way, which happens more than you would like. A page that has been replaced by a picture has nothing left to miss.

How to check the file you already have

Do not take anyone’s word for this, including ours. Two minutes, no tools you do not already have:

Open the redacted PDF in any viewer. Select all the text on the redacted page — Ctrl+A, or drag across the black box — and copy it. Paste it somewhere plain, like a browser address bar or a text editor. If the redacted words appear, they were never removed.

The more thorough version is to run the file through a text extractor and read the output for the page you redacted. Docqify has one that runs in your browser, so you are not uploading a document you already believe is sensitive in order to find out whether it still is.

Do this on any redacted file you are about to send. If it came from a tool that draws boxes, the words are still in it.

The tools this guide refers to

All of them run in your browser. Nothing you open is uploaded, which matters more here than anywhere else on this site.

Redact a PDF properly

Questions

How to redact a PDF — the details

Every tool, one place

All PDF Tools, Right Here

Powerful tools, the same privacy, all in one place. Every one of them runs in your browser.