Search and Replace Text within WebViewer, DOCX Editor, and Spreadsheet Editor

Search and replace for PDF documents in the WebViewer requires the Content Edit add-on.

All three document viewers contain built in UIs for performing the search and replace functionality in their respective file types.

WebViewer Search and Replace UI

Search and replace can also be handled uniformly across all three viewers using APIs:

JavaScript

1WebViewer(...)
2.then(instance => {
3 const documentViewer = instance.Core.documentViewer;
4
5 documentViewer.addEventListener('documentLoaded', async () => {
6 const searchStream = documentViewer.search('search_term'); // Setting up stream using your string to search.
7 const searchResults = await searchStream.getAll(); // Wait for all results.
8 await documentViewer.replace(searchResults, ' replace_term'); // Replace results using string.
9 });
10});

Here is another sample that replaces all of the search results found only on page one:

JavaScript

1WebViewer(...)
2.then(instance => {
3 const documentViewer = instance.Core.documentViewer;
4
5 documentViewer.addEventListener('documentLoaded', async () => {
6 const searchStream = documentViewer.search('search_term'); // Setting up stream using your string to search.
7 const searchResults = await searchStream.getAll(); // Wait for all results.
8 const firstPageResults = searchResults.filter(result => result.pageNum === 1); // Search results can be filtered or reordered but not modified.
9 await documentViewer.replace(firstPageResults, ' replace_term'); // Replace results using string.
10 });
11});

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales