Performs a "find", "find next" or "find previous" search operation on the text of the document.
findText
Data that contains the text to find.
isFirst
true to perform a "find" operation, otherwise, continues searching for either next or previous text.
findNext
true to perform a "find next" operation; otherwise, false to perform a
"find previous" operation.
A list of the text items found, or null if no next was found with this operation.
Find and LastFindText are used together to perform "find", "find next" and "find previous" text search operations.
Typical applications that perform text search contain a menu item for "Find", "Find Next" and "Find Previous". The following explains how to use Find and LastFindText to perform these operations.
"Find Next" and "Find Previous" are used to continue searching from the last location. Therefore, at the beginning of the program, these are not called and the corresponding UI elements should be disabled. Note that some applications select to check this state and call "Find" when "Find Next" is called without previous data. In either case, the data for the last find operation is an instance of DocumentViewerFindText object that is set to null, DocumentViewerText saves a value that can be used for this purpose in the LastFindText property which will have a value of null when a new document is set in the viewer.
When the user select "Find" from the application menu, the options for the search must be collected. This is performed by creating a new instance of DocumentViewerFindText and setting the options. Typical "Find Text" dialogs contain options that matches these properties as follows:
The text to find: Set this in DocumentViewerFindText.Text
Whether to perform case sensitive search and if whole words must be matched: Set these in DocumentViewerFindText.MatchCase and DocumentViewerFindText.WholeWordsOnly
If search is restricted to the current page or includes all in the document: Set these in DocumentViewerFindText.GotoNextPage and DocumentViewerFindText.PageNumber
Once the options are collected, call the Find method using the following parameters:
Find(options, true, false)
which is false to indicate that the search must progress forward from current location (start at the document). The method will run and return either the text items found or null otherwise. If text was found (the return value is not null), then the return value can be used to parse the text characters to show to the user or if DocumentViewerFindText.AutoSelect and DocumentViewerFindText.AutoEnsureVisible were set to true (default value), then document viewer will automatically select this text and highlight in the viewer and optionally, pan the image viewer to ensure that the value is visible in the current view. At this point, typical applications leave the find dialog open with the same option and prompt the user to either stop the search (close the dialog) or perform a "find next" or "find previous" operation from the search dialog itself. In either case, "find next" and "find previous" can be performed without the need to the DocumentViewerFindText object created in this step, as explained later. If null is returned, then the search could not find any matching text in the page or document. The application should show a warning message or indicator to the user to signal that the operation is complete. In this case, either exit the dialog or prompt the user to enter a new value.
If text items were found using the first Find, then a copy of the DocumentViewerFindText object will be stored in the LastFindText property. This object contains the same text and options passed by the user as well as internal data used by the viewer to track the location in the page and document of the search. Typical applications will check the value of LastFindText against null and enable the "Find Next" and "Find Previous" UI elements accordingly. To perform a "find next" operation, call Find with the following parameters:
Find(documentViewerText.LastFindText, false, true)
Find(documentViewerText.LastFindText, false, false)
At any time, call Find with a brand new DocumentViewerFindText object instead of the value of LastFindText to reset the search and start from the beginning of the document.
The LEADTOOLS Document Viewer demo uses the above to perform text search operations. Refer to the demo source code for a full example.
Calling Find required obtaining the text of the page(s) using DocumentPage.GetText, the viewer can automatically perform this when the value of AutoGetText is true.
Find performs the action of selecting text in the page or document by calling SetSelectedTextItems.
Start with the example created in DocumentViewer, remove all the code in the Example function and add the code below.
When the user clicks the Example button, we will try to find the word "LEAD" in the current page, and continue with finding next occurance until we reach the end of the page.
Products |
Support |
Feedback: Find Method (DocumentViewerText) - Leadtools.Documents.UI |
Introduction |
Help Version 19.0.2017.3.21
|