Redacting a PDF: why a black box is not enough
How Redact PDF removes text, not only hides it: PDFium calls, the saved-file check, one missing call that kept the text, and what is not covered.
Our sample file for Redact PDF is a fictional statement. Page 1 has a heading, a line that must survive, an account number, a total and an image-only “signature” block. Page 2 repeats the total. In the test we search for the total, mark the account line and the signature block, and redact. Then we extract the text from the saved file with a second program, PDF.js, and check three things: the total and the account number are gone, the heading and the “keep this line” text are still there, and the signature pixels are gone from the embedded image.
That test exists because a black rectangle looks the same whether or not anything was removed under it.
Hiding and removing are different operations
A rectangle drawn on a page is another object in the page content. The text object under it is still in the file, and a text extractor, a copy and paste or a search will still find it. Our own Annotate PDF tool draws rectangles, and its page says plainly that visual marks are not redaction. The same warning is on the watermark, crop and page-layout tools: cropping clips what is visible and does not remove the hidden content.
Redaction has to change the content of the page. For text that means cutting the text objects inside the marked area. For images it means erasing the pixels inside it. Only after that does a black box make sense, as a visible sign of where something was.
What the engine does
Redact PDF runs on PDFium, in the build published as @embedpdf/pdfium 2.15.1, compiled to WebAssembly and pinned in the repository. On 29 September 2026 we tried it on a generated file and found that EPDFText_RedactInRect followed by EPDFPage_ApplyRedactions left no extractable characters in the area.
The page offers three ways to mark an area: drag with a mouse, pen or finger, move and resize a mark with the keyboard, or search for a phrase and mark every match. In the test the search for “148.50” found two matches, one on each page. The code then does the following for each marked page, in this order:
- Annotations and form fields on the page are flattened into the content, so that their appearance is redacted too and a field value cannot sit behind a mark.
- Each marked area goes through
EPDFText_RedactInRect. EPDFPage_ApplyRedactionsruns for any redaction annotations on the page.- A black rectangle is added over each area.
FPDFPage_GenerateContentrewrites the page content.- The document is saved as a copy.
What did not work first
Step 5 is the one we nearly missed. Without FPDFPage_GenerateContent, the removed text stays in the saved file. The note in our engine table marks the call as required. The tests read the saved output with PDF.js, a different library from the one that made it, so a leftover shows up there.
Two smaller traps cost time. PDFium’s initialization crashed when the file path contained Cyrillic letters. The fix is to pass our own thisProgram: "/pdfium" at startup. And PDFium’s own “last error” value was unreliable for encrypted files, so the code looks for an /Encrypt entry itself and refuses those files.
The check on the saved file
The page does not trust the redaction step. The worker redacts a fresh copy of the opened document, so the source stays unchanged for retries. It saves the copy, opens the saved bytes again and reads the text inside every marked area, slightly inset so that neighbouring letters touching the border do not count. If any area still has text, no file is offered and the page says “Text was still found in a marked area.” If the page count of the result differs from the source, no file is offered either.
What the four tests cover
| Test | What it checks |
|---|---|
| Marked and searched areas | The totals and the account number are gone in PDF.js output; the heading and the kept line stay; the signature block renders black and has no ink-coloured pixels left in any embedded image |
| Rotated page | A search on a page rotated by 90 degrees marks the right place; the visible text beside it stays |
| Form fields | A text field with a secret value under a mark is flattened and removed; another field outside the mark keeps its value |
| Limits | An encrypted file is refused with a password error; a file over the page limit is refused |
What is not covered
The limits are 20 MB and 100 pages in, up to 500 marked areas, and 40 MB out. Redaction applies to the areas you mark. We have not verified that document properties are cleaned. Title, author, XMP metadata and attachments can carry the same names or numbers as the page, and Redact PDF does not touch them. Our Sanitize PDF tool removes scripts, attachments, XMP and the Info dictionary, but it is a separate tool, and Redact PDF does not call it. Text that is only a picture of text, such as a scan, has no text object, so a search will not find it. Mark the area by hand and the pixels are erased and covered in black.
All the test files are synthetic. We have not run the engine on real redaction work.
How we measured
The unit tests are in packages/processors/src/experiments/pdfium-core.test.ts and run against the real WASM build. A browser test in tests/laboratory-engines/p3b-engines.spec.ts opens /en/redact-pdf/ with the sample file, marks areas by search and by keyboard, and checks the result. The sample is synthetic and has no personal data. The engine page came with the PDF engine utility batch of 29 September 2026.
Try it
Redact PDF is in the Laboratory. The page has a sample file, and the result can be checked as described above.