TextSearch Class |
//... Initialize PDFNet ... PDFDoc doc = new PDFDoc(filein); doc.initSecurityHandler(); int mode = TextSearch.e_whole_word | TextSearch.e_page_stop; UString pattern("joHn sMiTh"); TextSearch txt_search = new TextSearch(); //PDFDoc doesn't allow simultaneous access from different threads. If this //document could be used from other threads (e.g., the rendering thread inside //PDFView/PDFViewCtrl, if used), it is good practice to lock it. //Notice: don't forget to call doc.Unlock() to avoid deadlock. doc.Lock(); txt_search.Begin( doc, pattern, mode, -1, -1 ); while ( true ) { TextSearch.ResultCode result = txt_search.Run(); if ( result.GetCode() == TextSearchResult.e_found ) { Console.WriteLine("found one instance: " + result.GetResultStr()); } else { break; } } //unlock the document to avoid deadlock. doc.UnLock();
Namespace: pdftron.PDF
public sealed class TextSearch : IClosable
The TextSearch type exposes the following members.
Name | Description | |
---|---|---|
TextSearch | Constructor and destructor. |
Name | Description | |
---|---|---|
Begin | Initialize for the search process. This should be called before starting the actual search.
with method run().
| |
Close | ||
Equals | (Inherited from Object.) | |
GetCurrentPage | Retrieve the number of the current page that is searched in.
If the returned value is -1, it indicates the search process has not been initialized
(e.g., begin() is not called yet); if the returned value is 0, it indicates the search
process has finished, and if the returned value is positive, it is a valid page number.
| |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetMode | Retrieve the current search mode. | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
Run | Search the document and returns upon the following circumstances:
Remarks
Note that this method should be called in a loop in ordre to find all matching instances;
in other words, the search is conducted in an incremental fashion.
| |
SetMode | Set the current search mode. For example, the following code turns on the regular
expression:
TextSearch ts = new TextSearch();
...
int mode = ts.getMode();
mode |= TextSearch.e_reg_expression;
ts.setMode(mode);
...
| |
SetPattern | Sets the current search pattern. Note that it is not necessary to call this method since
the search pattern is already set when calling the begin() method. This method is provided
for users to change the search pattern while searching through a document.
| |
SetRightToLeftLanguage |
Tells TextSearch that the document reads from right to left.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |