redact
Redact PDF
Remove text and pictures from a document so that they are gone from the file.
- Reads
- a PDF — application/pdf
- Writes
- one file — PDFs
- Tool page
- /redact-pdf
Example
Take a name out of a document, rather than draw a box over it.
Given
- statement.pdf — a PDF of written text
From code
import { loadDocument, runOperation } from '@pagecraft/core';
const statement = await loadDocument({ bytes, name: 'statement.pdf' });
const [output] = await runOperation('redact', [statement], {
find: 'Priya Nair',
caseSensitive: false,
});
From a shell
pagecraft redact statement.pdf --find 'Priya Nair'
What comes back
One PDF of 1 page, no longer containing “Priya Nair”.
This example is run by the test suite. If it stopped being true, the build would fail.
Options
find--find
string
Remove every
Text to remove wherever it appears in the document.
regex--regex
boolean
Regular expression
Treat what was typed as a pattern rather than as the text to find.
Default: false
caseSensitive--case-sensitive
boolean
Match case
Default: false
wholeWord--whole-word
boolean
Whole words only
So that 'ann' does not take the middle out of 'annual'.
Default: false
regions--regions
object[]
Areas
Rectangles to clear, in points from the bottom-left corner of the page as it is shown.
color--color
string, '#rrggbb'
Box colour
The colour of the box drawn where the content was.
Default: '#000000'
padding--padding
number (pt)
Margin
How far past the text to remove, so that no part of a letter is left behind.
Default: 1
What it cannot do
- A scanned page holds a picture of words, and nothing here can read it. Run OCR over it first, or give the area as a rectangle.
- A rectangle that reaches into a word takes the rest of that word — up to eight letters of it, or two where the file does not say which of its codes is a space — because the rectangle a search works out is right to within a letter rather than to the glyph, and half a name left on the page is worse than a whole one removed.
- Text that is not upright on the page — a rotated watermark, a sideways heading — is removed a run at a time rather than a letter at a time, because a reader reports no position inside a turned run.
- Text is searched over the whole document. Redacting a name on one page and leaving it on the next is not something this Operation will do; to clear part of a page and nothing else, give the area as a rectangle.
- Drawings are not removed: a chart or a signature under a rectangle is covered by the box rather than taken out of the file. Text and pictures are.
- A picture stored as a fax, a JBIG2 scan or a JPEG 2000 cannot be edited by this build, so one lying under a rectangle is removed whole rather than in part.
- What the document no longer refers to is dropped, so a file that had been saved incrementally comes back without its earlier versions.
- The title, the author and every other document detail are removed, because they routinely restate what was redacted.
- An annotation or a form field whose own text is what is being removed is deleted wherever on the page it sits, not only where it lies under a rectangle: a value a reader hands back on demand is a copy of the thing that was redacted.
- A bookmark, a file attached to the document or a named destination is left as it was. What is cleared is the page content, the annotations over it, the tagging that described it and the document details.
- A protected document is written back out in the clear. Protect it again if it needs a password.