Section:

Document Redaction in Salesforce

Apryse offers PDF Redaction, a safe and secure removal of content on document formats such as PDF. This guide will help you utilize all of Apryse's Redaction capabilities in Webviewer alongside Salesforce Lightning Components.

Getting Started

We recommend familiarizing yourself with the Overview page to learn how to correctly use a config.js file. If you are using a version of WebViewer older than 8.0+, you should also learn about readerControl before getting started.

WebViewer configuration required for redaction

In your LWC where you initialize WebViewer (you can check out pdftronWvInstance.js in our sample repository). This shows you how to enable redaction:

JavaScript

1//snipped for brevity
2const viewerElement = this.template.querySelector('div');
3
4const viewer = new PDFTron.WebViewer({
5 path: libUrl,
6 custom: JSON.stringify(myObj),
7 config: myfilesUrl + '/config_apex.js',
8 fullAPI: true // this must be set to true
9 enableRedaction: true, // this must be set to true
10 // l: 'YOUR_LICENSE_KEY_HERE',
11}, viewerElement);

Note: You need to use the pdf_full.zip file in your /staticresources/ folder to access full API, which is required for redaction.

Open a document

To perform redaction on a document, open it in WebViewer. Check opening documents guide to learn more.

Creating redactions manually using the UI

Review creating redaction guide for creating redactions with the WebViewer UI.

Search and redact

You can use search to highlight single or all occurences of a search term. You may also use regular expressions, which allows to target e-mail addresses, phone numbers, credit card numbers, etc. See more in our searching documents guide.

When performing your search, add a searchListener that marks your search results for redaction like so:

JavaScript (v8.0+)

1const searchListener = (searchTerm, options, results) => {
2 // add redaction annotation for each search result
3 const newAnnotations = results.map(result => {
4 const annotation = new Annotations.RedactionAnnotation();
5 annotation.PageNumber = result.pageNum;
6 annotation.Quads = result.quads.map(quad => quad.getPoints());
7 annotation.StrokeColor = new Annotations.Color(136, 39, 31);
8 return annotation;
9 });
10
11 annotManager.addAnnotations(newAnnotations);
12 annotManager.drawAnnotationsFromList(newAnnotations);
13};
14
15instance.addSearchListener(searchListener);

JavaScript (v7.0+)

1const searchListener = (searchTerm, options, results) => {
2 // add redaction annotation for each search result
3 const newAnnotations = results.map(result => {
4 const annotation = new Annotations.RedactionAnnotation();
5 annotation.PageNumber = result.pageNum;
6 annotation.Quads = result.quads.map(quad => quad.getPoints());
7 annotation.StrokeColor = new Annotations.Color(136, 39, 31);
8 return annotation;
9 });
10
11 annotManager.addAnnotations(newAnnotations);
12 annotManager.drawAnnotationsFromList(newAnnotations);
13};
14
15readerControl.addSearchListener(searchListener);

Then run your search using either instance.searchText(searchTerms, searchOptions) or instance.searchTextFull(searchTerms, searchOptions). Once you have the desired search term(s) highlighted, you can call instance.Core.documentViewer.getAnnotationManager().applyRedactions(); to redact these items.

Creating redactions programmatically

Review the guide for creating redaction for more on creating redactions programmatically.

Sample project

You can review the Salesforce PDF App to showcase an end-to-end example of search, and how you can leverage it for redaction and content replacing on our Github repository.

Live demo

Check out this live redaction demo (hosted outside of Salesforce).

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales