Redaction ​
Redaction permanently removes sensitive content from a PDF. It usually has two phases:
- Create redaction marks that identify regions to redact.
- Apply redaction to permanently delete text, images, or graphics under the marked regions.
With the full UI (UIExtension), redaction tools let users create marks and apply redaction after confirmation; sensitive-word hits from search can also feed redaction marks. Use the PDFPage and PDFDoc APIs in this topic when you need batch marking, marks from search results, or custom control over applying redaction.
Related APIs include:
PDFPage.markRedactAnnot(): Create redaction marks in page regions.PDFDoc.makeRedactByPages(): Mark entire pages for redaction.PDFDoc.searchText(): Search for sensitive terms and obtain match regions for redaction marks.PDFDoc.applyRedaction(): Apply redaction marks and permanently remove content under them.PDFDoc.getFile(): Export the redacted PDF.PDFPage.getDevicePoint(),PDFPage.reverseDevicePoint(),PDFPage.reverseDeviceRect(): Convert between Viewer and PDF coordinates for marks from pointer or render regions.
WARNING
After applyRedaction(), original content in redacted regions is permanently removed from the PDF. Prompt users to confirm before applying and keep a backup of the source file.
Mark regions for redaction ​
PDFPage.markRedactAnnot(rects) marks regions on a page. Input regions use PDF coordinates.
javascript
const page = await pdfDoc.getPageByIndex(0);
const redactionAnnots = await page.markRedactAnnot([
{
left: 100,
right: 300,
top: 720,
bottom: 680
}
]);Multiple rectangles can belong to one redaction annotation as multiple regions.
javascript
await page.markRedactAnnot([
{ left: 100, right: 300, top: 720, bottom: 700 },
{ left: 100, right: 260, top: 690, bottom: 670 }
]);Mark pages for redaction ​
PDFDoc.makeRedactByPages(pages) marks specified pages entirely for redaction.
javascript
await pdfDoc.makeRedactByPages([0, 2]);Mark redaction after search ​
Combine PDFDoc.searchText() with match rectangles to create redaction marks.
javascript
const result = await pdfDoc.searchText([0], ['secret'], {
wholeWordsOnly: true,
caseSensitive: false
});
const page = await pdfDoc.getPageByIndex(0);
const rects = result[0].flatMap(item => item.rects);
if (rects.length > 0) {
await page.markRedactAnnot(rects);
}Apply redaction ​
PDFDoc.applyRedaction() applies redaction marks and permanently removes content beneath them.
javascript
const result = await pdfDoc.applyRedaction();
if (result === false) {
throw new Error('Failed to apply redaction');
}Export and save the document after applying.
javascript
const file = await pdfDoc.getFile({
fileName: 'redacted.pdf'
});Relationship to annotations ​
Before application, redaction marks are annotations that users can preview, adjust, or delete in the UI. After application, marks are processed and underlying content is removed from the document.
To control who can create, delete, or edit redaction marks, use the annotation authority manager.
Coordinates ​
markRedactAnnot() uses PDF coordinates with the page origin typically at the bottom-left, in points. Convert from pointer or Viewer device pixels when needed.
See:
PDFPage.getDevicePoint(): PDF to device coordinates.PDFPage.reverseDevicePoint(): Device to PDF coordinates.PDFPage.reverseDeviceRect(): Device rectangle to PDF rectangle.
Notes ​
- Redaction is irreversible; confirm with users before applying.
- Creating marks alone does not remove content; call
applyRedaction()to remove it permanently. - For image text on scanned pages, marks must cover the image content.
- Search-based redaction suits extractable text; scanned documents usually need OCR before text search.