This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/web/redaction/built-in-ui.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. JavaScript PDF redaction tools | Nutrient

In addition to being able to create redactions programmatically, you can create and customize redactions via the UI Nutrient provides.

Required toolbar tools

For redaction workflows, include both required tools explicitly in your toolbar configuration:

  • redact-text-highlighter
  • redact-rectangle

Set the toolbar items array with NutrientViewer.Configuration#toolbarItems or NutrientViewer.Instance#setToolbarItems:

const toolbarItems = NutrientViewer.defaultToolbarItems.concat([
{ type: "redact-text-highlighter" }, // Text redaction tool.
{ type: "redact-rectangle" } // Area redaction tool.
]);
NutrientViewer.load({
// ...
toolbarItems
});

Text highlighter

When the text redaction tool is active, you can drag a selection across regions of text, and a new redaction annotation will be outlined throughout it. It works in a way similar to how the text highlighter tool does.

Additionally, this interaction can be programmatically enabled by setting the NutrientViewer.ViewState#interactionMode property to NutrientViewer.InteractionMode.REDACT_TEXT_HIGHLIGHTER. Refer to our customize existing tools guide to learn more.

Area highlighter

When the area redaction tool is active, you can draw a rectangle around the pages of a document, and a new redaction annotation matching the region drawn will be added. It works in a way similar to how the tool used to create rectangle annotations does.

Additionally, this tool can be programmatically enabled by setting the NutrientViewer.ViewState#interactionMode property to NutrientViewer.InteractionMode.REDACT_SHAPE_RECTANGLE. Refer to our customize existing tools guide to learn more.

Both the text highlighter redaction button and the area highlighter redaction button are hidden by default in our UI and are only available when explicitly set via the API.

NutrientViewer.load({
toolbarItems: [
...NutrientViewer.defaultToolbarItems,
{ type: "redact-rectangle" },
{ type: "redact-text-highlighter" }
]
});

Text selection

Another way of creating a text redaction is by first selecting text and then choosing the redaction toolbar from the contextual tooltip that appears.

Text selection menu

Previewing redactions

To preview redactions and see how they’d look when applied without removing any document content, set the NutrientViewer.ViewState#previewRedactionMode flag to true:

instance.setViewState((v) => v.set("previewRedactionMode", true));

Applying redactions

To actually redact the document after all the redaction annotations are added, call the NutrientViewer.Instance#applyRedactions() API method. This will overwrite the existing document, removing content irreversibly.

Do not allow final export before applyRedactions() succeeds when compliance/sanitization is required.

For a canonical production sequence (mark → apply permanently → export) and export recommendations, refer to the production-safe redaction workflow guide.

await instance.applyRedactions();
console.log('The document has been redacted.');

The redaction annotations will be removed once the document has been redacted and the affected content has been removed.

Redacting graphic objects shared across pages

A PDF can draw the same object on several pages. That object can be an image, such as a logo. It can also be a form XObject, a reusable block of page content that can hold text, images, and vector graphics. A watermark and the field labels of a flattened form are common examples of shared text.

When a redaction removes content from a shared object, it removes that content from every page that draws the object. If the redaction removes text from a shared form XObject, the filled redaction area also appears on those pages.

For example, when you redact part of a logo shown on every page, the same part is redacted on all of them. Redacting shared images this way is compatible with how Adobe Acrobat does it.

PDF tools can store an identical image or form XObject once and reuse it on several pages to reduce file size. If some pages must keep content you redact on others, those pages can’t share the object. In that case, give each page its own copy of the shared objects, including nested ones, before you apply redactions. Redaction doesn’t split shared objects for you, so use a PDF processing tool to do this before you load the document.

Two objects can look the same and still be separate objects, so they aren’t always redacted together. Review every page of the redacted document, including pages you didn’t mark.