PDF.js Express Plusplay_arrow

Professional PDF.js Viewing & Annotations - Try for free

side menu

Get Started

play_arrow

Learn more

play_arrow

Common use cases

play_arrow

Open a document

play_arrow

Save a document

play_arrow

Viewer

play_arrow

UI Customization

play_arrow

Annotations

play_arrow

Collaboration

play_arrow

Forms

play_arrow

Signature

play_arrow

Searching

play_arrow

Measurement

play_arrow

Compare

play_arrow

Advanced Capabilities

play_arrow

PDF.js Express REST API

play_arrow

Migration Guides

play_arrow

Basic searching

The following features are available in:

check

PDF.js Express Viewer

help_outline

PDF.js Express Viewer is a free viewer with limited capabilities compared to PDF.js Express Plus

check

PDF.js Express Plus

help_outline

PDF.js Express Plus is a commercial PDF SDK for viewing, annotating, signing, form filling and more

PDF.js Express provides a few different search APIs depending on your use case.

Searching a document one by one

The searchText API searches the document for your searchValue, and jumps to the first found result.

To jump to next next result, the function must be called again.

WebViewer(
  { ...options },
  document.getElementById('viewer')
).then(instance => {

  const { documentViewer } = instance.Core;

  // search can only be performed after a document is loaded
  instance.documentViewer.addEventListener('documentLoaded', () => {
    const searchValue = 'your_search_text'

    instance.UI.searchText(searchValue, {
      ...options // see the API reference for options
    })
  })
})

Searching a full document

The searchTextFull API searches the entire document, and highlights all results.

WebViewer(
  { ...options },
  document.getElementById('viewer')
).then(instance => {

  const { documentViewer } = instance.Core;

  // search can only be performed after a document is loaded
  documentViewer.addEventListener('documentLoaded', () => {
    const searchValue = 'your_search_text'

    instance.UI.searchTextFull(searchValue, {
      ...options // see the API reference for options
    })
  })
})

Both the APIs above can accept a regex string. Note that the regex must be passed as a string, and the regex option must be set to true.

WebViewer(
  { ...options },
  document.getElementById('viewer')
).then(instance => {

  const { documentViewer } = instance.Core;

  // search can only be performed after a document is loaded
  documentViewer.addEventListener('documentLoaded', () => {

    // Find any URLs that end with .com
    const searchRegex = 'www(.*)\.com.'

    instance.UI.searchTextFull(searchRegex, {
      regex: true
    })
  })
})

Changing highlight colors

To change the color of the search result highlights, you can use the setSearchHighlightColors.

You can pass either a valid CSS color string, or an instance of the Color class,

WebViewer(
  { ...options },
  document.getElementById('viewer')
).then(instance => {

  const { documentViewer, Annotations } = instance.Core;

  documentViewer.setSearchHighlightColors({
    searchResult: new Annotations.Color(0, 0, 255, 0.5),
    activeSearchResult: 'rgba(0, 255, 0, 0.5)'
  });
})

Advanced searching

Please see this guide for more advanced guides on searching,