The black box doesn't delete the text
Draw a black rectangle over a name in a PDF, export the file, then reopen it with pdf.js and call getTextContent() . The name comes back. Word for word, character for character. That was the first thing I ran into when I started building a redaction tool that runs entirely in the browser. A black rectangle is a drawing instruction. It sits on a layer above the page. The text object underneath…
When building a redaction tool that operates entirely in the browser, one quickly encounters the issue of black rectangles failing to remove text from a PDF. A black rectangle is merely a drawing command, sitting atop the page and not affecting the underlying text object. Most tools in this space handle this problem in one of two ways: rewriting the content stream to actually delete the text, or rendering the page to an image and discarding the text layer.
Both approaches work, but they present a problem: after the tool claims completion, it is unclear whether the text was genuinely removed or merely replaced with an image. To address this, I implemented a third approach – a manual check button that the user presses to verify the redaction results.
The character counting mechanism involves utilizing pdf.js to retrieve the text items for a page and converting the coordinates from PDF space to the viewport coordinate system. By iterating through the content items, the tool checks if the coordinates of each text item fall within the specified box dimensions. If so, the length of the text string is added to the total count of characters remaining.
The implications of this process are significant. After redaction, the tool reopens its output and counts the remaining extractable characters. In cases where the text was actually removed, the tool reports zero characters across the pages. However, if the text remains as an image, the tool reports a non-zero character count, misleading the user as to the effectiveness of the redaction. The distinction between these outcomes is crucial, as it directly impacts the user's trust and understanding of the tool's results.
To illustrate, consider a test file with three pages, where one page is marked for redaction. The export process replaces that page with an image, while the other two pages are left unchanged. Upon re-checking the output, the tool correctly identifies 210 extractable characters remaining across two pages. In contrast, if all three pages were marked for redaction, the tool reports 0 extractable characters across three pages.
For a scan file containing no text layer, the check before exporting highlights this absence, avoiding confusion with a zero character count. Similarly, a box drawn over empty whitespace is accurately identified as a "miss" by the check. However, when a box covers a line containing text, such as a fake name and SSN, the tool reports 50 characters as remaining within the marked area.
The competitor analysis revealed that several existing tools share this limitation of reporting a zero character count after redaction, even when the text remains as an image. This lack of transparency undermines the user's trust in the tool's capabilities. My approach of providing clear, actionable feedback on the character count, rather than merely stating "done," encourages users to actively engage with the results and make informed decisions about the redaction process.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.