You Don't Need Acrobat to Redact a PDF: A Browser‑Native Pipeline Using pdf.js and pdf-lib
Описание и применение
Пайплайн для безопасного редактирования PDF в браузере: рендеринг страниц в canvas, наложение черных прямоугольников, конвертация в PNG и создание нового PDF с pdf-lib, полностью удаляющего исходный текст и скрытые данные.
Задача
Redaction tools that only overlay black boxes on PDFs fail to remove the underlying text and can leave hidden data from incremental updates, making sensitive information recoverable.
Результат
The pipeline produces a PDF where sensitive text is irrecoverably removed, with no traces of original content or incremental revisions, and the process runs entirely client‑side in the browser.
Рабочий процесс
- 1. Read PDF as ArrayBuffer in browser; parse with pdf.js.
- 2. Render each page to an HTML canvas at desired resolution.
- 3. Draw user‑selected redaction shapes directly onto the same canvas using 2D context.
- 4. Convert the canvas to a PNG data URL, flattening all content.
- 5. Create a fresh PDFDocument with pdf-lib and embed each PNG as a page image.
- 6. Save the new PDF, discarding the original file entirely.
Доказательства
A black rectangle sitting on top of that structure does not delete anything. It just draws over it.
The only approach that reliably satisfies all three is rasterization.
- Дата записи: 2026-09-15T13:15:19.945Z