Using Webviewer, how do I search and redact text from my document before viewing the document?

Question:

How can I search a document for strings of text and apply redactions before viewing the document, using WebViewer API?

Answer:

You can accomplish this client side by using the TextSearch API along with the Redaction API in WebViewer.

This code sample searches the document for all instances of text you want to redact (specified in a regex pattern) using the TextSearch API, creates redaction annotations based on the coordinates of the found text strings, and then redacts them from the document using the Redaction API.

Note: If you want to be able to review the annotations in WebViewer before applying annotations to the document, check out this community post.