Highlight custom search results

Q: How can I implement custom search and then highlight the results programmatically?

A: This can be achieved by implementing the following functionalities:

The code for this will look like:

Copy
1
2
3
4
5
6
7
8
9
10
const results = await instance.search("hello");

results.forEach(result => {
  const annotation = new PSPDFKit.Annotations.HighlightAnnotation({
    pageIndex: result.pageIndex,
    rects: result.rectsOnPage,
    boundingBox: PSPDFKit.Geometry.Rect.union(result.rectsOnPage)
  });
  instance.createAnnotation(annotation);
});

This has been tested with PSPDFKit for Web 2019.5.3