`Search`
component that can be used to create a custom search control.Method | Description | From |
---|---|---|
`clearHighlights` | Clear the highlights | 2.4.0 |
`highlight` | Highlight multiple keywords | 2.4.0 |
`jumpToNextMatch` | Jump to the next match | 2.4.0 |
`jumpToPreviousMatch` | Jump to the previous match | 2.4.0 |
`highlight`
function accepts a single or an array of keywords. Each keyword can be a `string`
, `RegExp`
or `FlagKeyword`
.`FlagKeyword`
type determines if we want to match the case or find the whole word:// The `FlagKeyword` type is available from the import// import { FlagKeyword } from '@react-pdf-viewer/search';interface FlagKeyword {keyword: string;matchCase?: boolean; // `false` by defaultwholeWords?: boolean; // `false` by default}
`document`
and `PDF`
words, but the results have to match the case of `PDF`
. So the `PDF`
words are highlighted, but `pdf`
words are not.import { searchPlugin } from '@react-pdf-viewer/search';const searchPluginInstance = searchPlugin();const { highlight } = searchPluginInstance;// Highlight keywordshighlight(['document',{keyword: 'PDF',matchCase: true,},]);
`matchCase`
and `wholeWords`
properties.`highlight`
, `jumpToNextMatch`
and `jumpToPreviousMatch`
methods, we can create a custom search control as following: