--- title: Redaction description: Mark text and areas for removal, review the marks, then remove the content for good. --- # Redaction Redaction removes content for good: the text, images and drawings under a mark are deleted from the file, not just covered up. It happens in two steps, as in Acrobat: first people **mark** what should go, and review it; then they **apply** the marks, and the content is gone. Register `redactionPlugin()` next to `interactionPlugin()` and `annotationPlugin()`, and use the `redact` tool: select text to mark it, or drag to mark an area: A mark is an annotation, so until it's applied, people can move it, resize it, delete it, and see it in other PDF apps. Applying it is what removes the content. ## Mark from code ```ts await redaction.markSelection(); // the selected text await redaction.markArea(page.ref, { x: 72, y: 100, width: 200, height: 40 }); await redaction.markPage(page.ref); // the whole page await redaction.markMatches({ text: 'Jane Doe' }); // every match in the document await redaction.markMatches({ text: '\\d{3}-\\d{2}-\\d{4}', regex: true }); // like a social security number ``` `markMatches` takes the same query as [search](../text/search), and resolves with `{ marks }`, one per match. ## Review the marks `usePendingRedactions()` lists the marks that haven't been applied yet, for a review panel: `redaction.clearPending()` removes every mark. `usePendingRedactions({ page: page.ref })` lists one page's. `redaction.pendingOn(page.ref)` lists one page's. ## Apply ```ts const result = await redaction.applyAll(); // every mark await redaction.apply([mark.ref]); // some marks await redaction.applyPages([page.ref]); // the marks on some pages ``` This can't be undone. Ask first, and say what else goes with it: annotations a mark overlaps are removed too, because they could show what was there. `estimateCollateral()` tells you how many: ```ts const { count } = redaction.estimateCollateral(); if (!(await confirm(`Redact? ${count} annotations under the marks will be removed too.`))) return; await redaction.applyAll(); ``` After applying, download the document with `{ mode: 'rewrite' }`, so the removed content isn't left in an earlier revision of the file. See [Saving & downloading](../documents/saving). ## What shows in place of the content By default a redacted area is black. Give it a label, such as "Classified", on a mark: ```ts await redaction.updateLabel(mark.ref, { overlayText: 'Classified', repeat: true }); ``` `repeat` fills the area with the label over and over; otherwise it shows once. The color and font of every mark are settings. ## Methods Everything `useRedaction()` gives you. | Method | What it does | | :------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | | `markSelection()` | Marks the selected text, one mark per page, and clears the selection. Resolves `{ marks }`. [Mark from code](#mark-from-code) | | `markArea(page, rect)`, `markPage(page)` | Marks an area of a page, or the whole page. Resolves `{ mark }`. | | `markMatches(query, { pages? })` | Marks every match of a [search](../text/search), or the ones on some pages. It replaces the current search. Resolves `{ marks }`. | | `unmark(refs)` | Removes marks without applying them. [Review the marks](#review-the-marks) | | `clearPending()` | Removes every mark | | `updateLabel(ref, { overlayText, repeat? })` | Sets the label a mark shows once it's applied; `overlayText: null` clears it. Resolves `{ mark }`. [What shows in place of the content](#what-shows-in-place-of-the-content) | | `listPending({ page? })` | The marks not applied yet, in page order, or one page's. In a component, use `usePendingRedactions()`. | | `getPending(ref)` | One mark, or `null` when it isn't a mark waiting to be applied | | `estimateCollateral(refs?)` | The other annotations applying would remove too, as `{ count, refs }`, for every mark or for the ones you pass. [Apply](#apply) | | `applyAll()` | Applies every mark in the document, on pages that haven't loaded too. Can't be undone. [Apply](#apply) | | `apply(refs)`, `applyPages(pages)` | Applies some marks, or the marks on some pages. Can't be undone. | | `canMark()`, `canUnmark(ref)`, `canUpdateLabel(ref)`, `canApply()` | Whether marking, removing a mark, changing its label and applying are allowed. [Permissions](#permissions) | | `getSettings()`, `updateSettings(changes)`, `resetSettings()` | Reads the settings, changes them while the app runs, or goes back to what you registered. In a component, use `useRedactionSettings()`. [Settings](#settings) | Applying resolves the result: each page's `status` (`'applied'` or `'unchanged'`) and how many other annotations were removed. Applying is all or nothing: when a page fails, no page changes and the promise rejects. Every method that returns a promise also takes a `signal` in its options, to cancel it. ## State | Field | What it is | Read once | | :------------- | :---------------------------------------------------------------- | :------------------------------------------------------- | | `pendingCount` | How many marks are waiting to be applied | `getPendingCount()`, or `getPendingCount(page)` for one page | | `applying` | Whether marks are being applied right now | `isApplying()` | | `lastResult` | The result of the last apply, from this session or another, or `null` | `getLastResult()` | The marks themselves come from `usePendingRedactions()`. Keeping them apart means a component that only shows the count doesn't re-render for every mark. ## Settings Set them when you register the plugin, and change them while the app runs with `redaction.updateSettings({ … })`; `redaction.resetSettings()` goes back to what you registered, and `useRedactionSettings()` gives you the current settings. | Setting | What it does | Default | | :--------------------- | :----------------------------------------------- | :---------- | | `overlay.fill` | The color of a redacted area | `'#000000'` | | `overlay.text.color` | The color of a label | `'#ffffff'` | | `overlay.text.fontFamily` | The label's font | Helvetica | | `overlay.text.fontSize` | The label's size, or `0` to fit the area (a repeated label then draws at 12pt) | `0` | ## Events | Event | Fires when | Carries | | :----------------- | :---------------------------------------------- | :------------------ | | `onApplied` | Marks were applied and the content is gone | `result`, `origin` | | `onPendingChanged` | A mark was added, changed or removed | `pages` | | `onSettingsChanged` | The settings changed | `settings`, `changedKeys` | ## Permissions | Permission | What it allows | Check | | :-------------------- | :-------------------------------------- | :---------------------- | | `annotations:create` | Marking | `redaction.canMark()` | | `annotations:delete` | Removing a mark before it's applied | `redaction.canUnmark(ref)` | | `annotations:update` | Changing a mark's label | `redaction.canUpdateLabel(ref)` | | `doc.redact` | Applying | `redaction.canApply()` | A mark is an annotation, so removing it or changing its label follows the same rules as any annotation, per mark. Applying also rewrites the pages and removes annotations, so `canApply()` needs `doc.pages.modify` and `doc.annotate.modify` as well. A reviewer who may mark but not apply can prepare redactions for someone else to approve. ## Good to know ### What is removed The characters under a mark are removed, so they can't be selected, searched or copied; the pixels of images inside it are erased; and the parts of lines, shapes and fills inside it are cut away. See [Redaction](/docs/engine/documents/redaction) for the details. ### Where the original is The local engine redacts a copy of the file the browser already has, so the original was on the user's device before it was redacted. With CloudPDF, redaction happens on your server. People who may only see the redacted version never receive the original: not the file, not its text, not its images. Redaction happens on your server, and people who may only see the redacted version never receive the original.