Introduction to Redaction

Redaction is the process of removing content from a PDF page. This not only involves obscuring the content, but also removing the data in the document within the specified region.

Redaction is generally used when you want to remove personally identifiable or sensitive information from a document in order to ensure confidentiality and conform to regulations and privacy laws, such as GDPR or HIPAA. By using the Redaction component, the original content of a PDF can’t be restored, thereby guaranteeing privacy.

Redaction is a two-step process.

  • First, redaction annotations have to be created in the areas that should be redacted. This step won’t remove any content from the document yet; it just marks regions for redaction.
  • Second, to actually remove the content, the redaction annotations need to be applied. In this step, the page content within the region of the redaction annotations is irreversibly removed.

For further in-depth information, check out Adobe’s PDF Redaction: Addendum for the PDF Reference.

Creating Redactions Programmatically

Via Redaction Annotations

You can create redaction annotations programmatically via RedactionAnnotation. Use the rects property to set the regions that should be covered by the redaction annotation. Additionally, the boundingBox needs to be set to a PSPDFKit.Geometry.Rect containing all the specified rects.

You also have a few customization options for how a redaction should look, both while the redaction annotation is in its marked state, which is when it has been created but not yet applied, and in its redacted state, which is when the content is effectively redacted:

  • overlayText can be used to set the text that should be displayed at a specified region when a redaction has been applied.
  • repeatOverlayText defines whether the overlay text should be drawn only once or repeated to fill the entire redaction area. This defaults to false, which means the overlay text is only drawn once. It has no effect if there is no overlay text specified.
  • color can be used to change the color of the overlay text. It has no effect if there is no overlay text specified. This defaults to PSPDFKit.Color.RED.
  • fillColor specifies the background color of the redaction area after it has been applied. The color is drawn on all the specified rects. This defaults to PSPDFKit.Color.BLACK.
  • outlineColor specifies the color used for the redaction’s border in its marked state. This defaults to PSPDFKit.Color.RED.

It is not possible to change the appearance once a redaction has been applied, since the redaction annotation will be removed from the document and the redaction will be part of the content of the document. This is an action that irreversibly replaces the original content under the specified region:

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const boundingBox = new PSPDFKit.Geometry.Rect({
  left: 25,
  top: 25,
  width: 175,
  height: 30
});

await instance.createAnnotation(
  new PSPDFKit.Annotations.RedactionAnnotation({
    pageIndex: 0,
    boundingBox,
    rects: new PSPDFKit.Immutable.List([boundingBox]),
    color: PSPDFKit.Color.ORANGE,
    overlayText: "REDACTED"
  })
);

The redaction annotation created with the above code snippet would look like what’s shown in the image below.

Marked State
Redacted State

Redaction Properties

Once a redaction is added to the document, its properties and appearance can be customized via the annotation toolbar.

The properties under the Preview label affect the redacted appearance (i.e. how the document will look once redactions are applied), while the outline color picker only affects the marked appearance of the annotation.

Via Search Criteria

It’s possible to use PSPDFKit for Web to automatically create redaction annotations based on specific search criteria. This could be a text term, a custom regular expression, or one of the built-in patterns that PSPDFKit for Web ships with.

PSPDFKit.Instance#createRedactionsBySearch() allows you to specify the search criteria, along with specifying a custom redaction annotation preset to be used when creating redactions based on search results. By default, content inside annotations will be also be included in the search results, but this can be adjusted with the searchInAnnotations Boolean property as part of the options argument.

Here is an example showing how to redact all occurrences of PSPDFKit on a document without including annotations:

1
2
3
const annotationIds = await instance.createRedactionsBySearch("PSPDFKit", {
  searchInAnnotations: false
});

You can also use one of our built-in patterns to quickly identify sensitive information that needs to be redacted. Here is an example of how to create redactions for every social security number found:

Copy
1
2
3
4
const annotationIds = await instance.createRedactionsBySearch(
  PSPDFKit.SearchPattern.SOCIAL_SECURITY_NUMBER,
  { searchType: PSPDFKit.SearchType.PRESET }
);

The full list of available patterns can be found in our documentation for PSPDFKit.SearchPattern. Please check our API documentation of PSPDFKit.Instance#createRedactionsBySearch() to learn more about the signature of this method.

Creating Annotations with the User Interface

Toolbar Items

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

For these, you have two toolbar items available: one for creating redactions by dragging the cursor around text Text highlighter redaction tool, and another one for drawing a rectangle over an arbitrary area Area redaction tool. In order to use these tools, you will need to set the toolbar items array appropriately (using PSPDFKit.Configuration#toolbarItems or PSPDFKit.Instance#setToolbarItems):

Copy
1
2
3
4
5
6
7
8
9
const toolbarItems = PSPDFKit.defaultToolbarItems.concat([
  { type: "redact-text-highlighter" }, // Text redaction tool.
  { type: "redact-rectangle" } // Area redaction tool.
]);

PDPDFKit.load({
  // ...
  toolbarItems
});

Text Highlighter

When the text redaction tool Text highlighter 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 PSPDFKit.ViewState#interactionMode property to PSPDFKit.InteractionMode.REDACT_TEXT_HIGHLIGHTER. Check our Controlling the Toolbar via API guide to learn more.

Area Highlighter

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

Additionally, this tool can be programmatically enabled by setting the PSPDFKit.ViewState#interactionMode property to PSPDFKit.InteractionMode.REDACT_SHAPE_RECTANGLE. Check out our Controlling the Toolbar via API guide to learn more.

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.

Previewing Redactions

To preview redactions and see how they would look when applied, without removing any document content, you can set the PSPDFKit.ViewState#previewRedactions flag to true:

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

Applying Redactions

In order to actually redact the document after all the redaction annotations are added, you can call the PSPDFKit.Instance#applyRedactions() API method. This will overwrite the existing document, removing content irreversibly:

1
2
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.

Licensing

Redaction is a feature that has to be purchased separately. If it’s not part of the license, the APIs and the UI changes mentioned above won’t function as described. The following list describes the expected behavior if Redaction is not part of your license: