`search` plugin provides a button or control to search for given keyword.npm install '@react-pdf-viewer/search';
import { searchPlugin } from '@react-pdf-viewer/search';// Import stylesimport '@react-pdf-viewer/search/lib/styles/index.css';
const searchPluginInstance = searchPlugin(props?: SearchPluginProps);
`SearchPluginProps` represents an object of the property:| Property | Type | Description | From |
|---|---|---|---|
`enableShortcuts`? | `boolean` | Enable shortcuts | 2.9.0 |
`keyword`? | `string`, `RegExp` or `FlagKeyword` | The initial keyword that will be highlighted in all pages | 2.0.0 |
`string[]`, `RegExp[]` or `FlagKeyword[]` | You can set multiple keywords to be highlighted initially | 2.1.0 | |
| See the Highlight multiple keywords initially example | |||
`renderHighlights` | `Function` | Customize the highlighted elements. See this example | 3.5.0 |
`onHighlightKeyword` | `Function` | Invoked when a keyword is highlighted | 2.4.0 |
| See the Add custom styles to the highlighted elements example |
`ctrl` + `F` to open the search popover.`searchPluginInstance` provides the following properties:| Property | Type | Description | From |
|---|---|---|---|
`Search` | `ReactElement` | Customizable search control | 2.2.0 |
| See the Create a custom search control example | |||
`ShowSearchPopover` | `ReactElement` | Customizable button to show the search popover | 2.0.0 |
| See the Customize the button to show the search popover example | |||
`ShowSearchPopoverButton` | `ReactElement` | The default button to show the search popover | 2.0.0 |
| See the Use the default button to show the search popover example | |||
`clearHighlights` | `Function` | Clear the highlights | 2.4.0 |
`highlight` | `Function` | Highlight multiple keywords | 2.4.0 |
| See the Highlight keywords programmatically example | |||
`jumpToMatch` | `Function` | Jump to a given match | 2.7.0 |
`jumpToNextMatch` | `Function` | Jump to the next match | 2.4.0 |
`jumpToPreviousMatch` | `Function` | Jump to the previous match | 2.4.0 |
`setTargetPages` | `Function` | Set the pages that you want to search in | 2.7.2 |
`search` plugin instance:<Viewer plugins={[searchPluginInstance]} />
`search` plugin provides other useful properties as following:import { NextIcon, PreviousIcon, SearchIcon } from '@react-pdf-viewer/search';
| Property | Type | Description | From |
|---|---|---|---|
`NextIcon` | `ReactElement` | The icon used to go to the next match in the document | 2.0.0 |
`PreviousIcon` | `ReactElement` | The icon used to go to the previous match in the document | 2.0.0 |
`SearchIcon` | `ReactElement` | The search icon | 2.0.0 |
`RenderSearchProps` adds new `isDocumentLoaded` property that indicates if the document is loaded`keyword` option`renderHighlights` option`Enter` automatically jumps to the next match when being focused on the keyword field`Ctrl + F`, or `Cmd + F` on macOS) when the mouse is inside the viewer container`clearHighlights` and `clearKeyword()` functions should remove all highlights when the keyword is empty`jumpToMatch()` function does not properly highlight keyword when the page is not in the virtual list`(`, `)`, `[`, `]`, `*` in the keyword`setTargetPages` function`jumpToMatch` function which jumps to the given match`highlight` function now returns a `Promise` that holds the results`onHighlightKeyword` option`SingleKeyword` type supports flags`rpv-search-text-highlight-current``Search` component`Previous` match or `Next` match button throws an error if the keyword is empty