How do I highlight text without an annotation?

Q: How do I highlight text without an annotation?

A: You can search for text using the search API and then highlight the text by adding a custom overlay item. Here is an example that will highlight all occurrences of the word “text” in the document:

instance.search('text').then(results => {
  results.toJS().forEach((result, i) => {
    const div = document.createElement('div')
    div.style.backgroundColor = '#808000'
    div.style.mixBlendMode = 'multiply'
    div.style.opacity = 0.5
    div.style.width = result.rectsOnPage[0].width + 'px'
    div.style.height = result.rectsOnPage[0].height + 'px'
    const item = new PSPDFKit.CustomOverlayItem({
      id: 'overlay' + i,
      node: div,
      pageIndex: result.pageIndex,
      position: new PSPDFKit.Geometry.Point({ x: result.rectsOnPage[0].left, y: result.rectsOnPage[0].top }),
    });
    instance.setCustomOverlayItem(item);
  })
}).catch(console.log);