DsPdfViewer lets you perform the Search operation using several advanced search options, such as match case, wild card, proximity, and more. By default, the Search icon is available in the toolbar, which, when clicked, opens the floating search bar. However, you can even place the Search panel in the sidebar by disabling the Floating search bar, as described ahead.
DsPdfViewer provides a floating text search bar at the top-right corner, just below the toolbar. You can open the floating text search bar using the toolbar icon () or by pressing Ctrl+F. Then, you can initiate the search by typing in the desired search term in the designated search input field. As you start typing, the search mechanism automatically begins searching for matches within the document, highlighting or displaying results in real-time as you type. This dynamic search process allows immediate feedback and helps a user quickly locate the relevant content.
The floating text search bar provides various advanced search options in the Settings () button to customize and fine-tune your search preferences. It eliminates irrelevant options and narrows down the scope of a search query.
You can close the floating text search bar using the Close () button or by pressing the ESC key when the search input is focused.
You can also use the sidebar search panel by setting ‘useFloatingSearchBar’ option to false. The sidebar search panel also provides advanced search options, along with displaying the count of total search results and the page number on which the specific result is found.
Refer to the following example code to use the sidebar search panel:
C# |
Copy Code
|
---|---|
// Use sidebar search panel instead of floating search bar. var viewer = new DsPdfViewer("#root", { useFloatingSearchBar: false }); |
The following sections explain the various advanced search options provided in DsPdfViewer:
This option finds all those instances in a PDF document that are written in the same case (lower or upper) as specified in the search query.
Example: If you search "test", the search results displays "test", "tests", "testing" but not "Test".
The 'Whole Word' option finds all those occurrences in a PDF document which contain the whole word as specified in the search query.
Example: If you search "demo", the search results displays "demo", "Demo" but not "demonstration", "demos".
This option finds all the occurences in a PDF document which starts with the characters specified in the search query.
Example: If you search "us", the search results display "us", "used", "Users" but not "various", "status".
This option finds all the occurences in a PDF document which ends with the characters specified in the search query.
Example: If you search "at", the search results display "at", "format", "treat" but not "attribute", "atom".
The 'Wildcard' option can be used to maximize the search results. You can type a part of a word and use any number of wildcard characters with it. DsPdfViewer supports two wildcard characters:
The 'Proximity' option can be used to search for two or more words that are separated by a certain number of words from each other. DsPdfViewer provides AROUND(n), NEAR(n), and ONEAR(n) operators, which can be used to specify the maximum count of words between search terms. The search results include only those words that are present on the same page of a PDF document.
AROUND(n): This operator matches results where search terms are within close proximity, preserving the order of the specified terms and allowing a defined distance between them.
NEAR(n): This operator matches results where search terms are within close proximity, ignoring the order of the terms.
ONEAR(n): This operator matches results where search terms are within close proximity, preserving the order of the specified terms.
Example: Consider the below text in a PDF document:
Several species of game fish live or spawn in wetlands. Hundreds, if not thousands, of invertebrates that form the food of birds also rely on water for most, if not all, phases of their existence. In fact, most all species of animals we have must spend at least part of the year in wetlands. To lose any more of these vital areas is almost unthinkable.
Case 1:
Search Query: species AROUND(8) wetlands
Result: species of game fish live or spawn in wetlands
Explanation: The words “species” and “wetlands” are present at a gap of 7 words from each other. In order to display this search result, the value of 'n' should be 7 or greater.
Case 2:
Search Query: species wetlands
Results: species of game fish live or spawn in wetlands
species of animals we have must spend at least part of the year in wetlands
Explanation: If operator AROUND(n) is not specified, the search results will include all words from query without any location constraint.
Case 3:
Search Query: species AROUND(8) wetlands AROUND(4) thousands
Result: species of game fish live or spawn in wetlands. Hundreds, if not thousands
Explanation: The words “species”, “wetlands” and "thousands" are present at the specified gaps.
Case 4:
Search Query: species NEAR(8) wetlands
Result: species of game fish live or spawn in wetlands
Explanation: The words “species” and “wetlands” are present at a gap of 7 words from each other. In order to display this search result, the value of 'n' should be 7 or greater.
Case 5:
Search Query: species ONEAR(8) wetlands
Result: species of game fish live or spawn in wetlands
Explanation: The words “species” and “wetlands” are present at a gap of 7 words from each other in the order specified. In order to display this search result, the value of 'n' should be 7 or greater.
Case 6:
Search Query: species AROUND(1) animals NEAR(7) part
Result: species of animals we have must spend at least part
Explanation: The words "species" and "animals" are adjacent with one word ("of"), and "animals" and "part" are separated by 6 words, which is within the limit of 7.
Case 7:
Search Query: "invertebrates that form" AROUND(2) food ONEAR(6) water
Result: invertebrates that form the food of birds also rely on water
Explanation: The phrase "invertebrates that form" is found within 2 words of "food," and “food” is within 6 words of "water," all while preserving the order of the terms.
The search results are highlighted all at once when 'Highlight all' option is checked in the search panel. The below code example shows how to change the default highlight colors by using the 'useCanvasForSelection' option:
Index.cshtml |
Copy Code
|
---|---|
var viewer = new DsPdfViewer('#root', { useCanvasForSelection: { selectionColor: 'rgba(0, 0, 195, 0.25)', highlightColor: 'rgba(255, 0, 0, 0.35)', inactiveHighlightColor: "rgba(180, 0, 170, 0.35)" } }); |