Search and Redact PDFs Using JavaScript

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.

Launch Demo

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’s an example showing how to redact all occurrences of PSPDFKit in a document, without including annotations in the results:

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, or use your own custom regex patterns.

Please refer to our API documentation of PSPDFKit.Instance#createRedactionsBySearch() to learn more.