Foxit PDF SDK
com.foxit.sdk.pdf.TextSearch Class Reference
Inheritance diagram for com.foxit.sdk.pdf.TextSearch:
com.foxit.sdk.common.Base

Public Member Functions

 TextSearch (Annot annot) throws com.foxit.sdk.PDFException
 Constructor, for a specified PDF annotation.
More...
 
 TextSearch (PDFDoc document, SearchCancelCallback cancel, int flags) throws com.foxit.sdk.PDFException
 Constructor, for a PDF document.
More...
 
 TextSearch (TextPage text_page) throws com.foxit.sdk.PDFException
 Constructor, for a specified text page.
More...
 
 TextSearch (TextSearch other)
 Constructor, with another text search object.
More...
 
 TextSearch (XFADoc xfa_document, SearchCancelCallback cancel) throws com.foxit.sdk.PDFException
 Constructor, for a specified XFA document.
More...
 
synchronized void delete ()
 Clean up related resources immediately. More...
 
boolean findNext () throws com.foxit.sdk.PDFException
 Search for next matched pattern.
More...
 
boolean findPrev () throws com.foxit.sdk.PDFException
 Search for previous matched pattern.
More...
 
int getMatchEndCharIndex () throws com.foxit.sdk.PDFException
 Get the index of the last character of current match pattern, based on current match page.
More...
 
int getMatchPageIndex () throws com.foxit.sdk.PDFException
 Get the page index, to which current match belongs.
More...
 
RectFArray getMatchRects () throws com.foxit.sdk.PDFException
 Get the rectangles of current match pattern.
More...
 
String getMatchSentence () throws com.foxit.sdk.PDFException
 Get the sentence that contains current match pattern.
More...
 
int getMatchSentenceEndIndex () throws com.foxit.sdk.PDFException
 Get the index of the last character of current matched pattern, based on the matched sentence.
More...
 
int getMatchSentenceStartIndex () throws com.foxit.sdk.PDFException
 Get the index of the first character of current matched pattern, based on the matched sentence.
More...
 
int getMatchStartCharIndex () throws com.foxit.sdk.PDFException
 Get the index of the first character of current match pattern, based on current match page.
More...
 
boolean isEmpty ()
 Check whether current object is empty or not.
More...
 
boolean setEndPage (int page_index) throws com.foxit.sdk.PDFException
 Set ending page index.
More...
 
boolean setPattern (String key_words) throws com.foxit.sdk.PDFException
 Set keywords to search.
More...
 
boolean setSearchFlags (int search_flags) throws com.foxit.sdk.PDFException
 Set search flags.
More...
 
boolean setStartCharacter (int char_index) throws com.foxit.sdk.PDFException
 Set starting character index, from where the search process is to be started.
More...
 
boolean setStartPage (int page_index) throws com.foxit.sdk.PDFException
 Set starting page index.
More...
 

Static Public Attributes

static final int e_SearchConsecutive = 0x04
 If set, match the key word consecutively when searching. For example, "CC" will be matched twice in "CCC".

 
static final int e_SearchMatchCase = 0x01
 If set, match the case of keyword when searching.

 
static final int e_SearchMatchWholeWord = 0x02
 If set, match the whole word of keyword when searching.

 
static final int e_SearchNormal = 0x00
 No special searching options.

 
static final int e_SearchNotMatchFullWidth = 0x20
 If set, to ignore full-width characters and treat all characters as standard ASCII or standard-width characters during searches.

 

Detailed Description

This class can construct text search in a PDF document/an XFA document/a text page or in a PDF annotation's appearance. It offers functions to do a text search and get the searching result:


Constructor & Destructor Documentation

◆ TextSearch() [1/5]

com.foxit.sdk.pdf.TextSearch.TextSearch ( PDFDoc  document,
SearchCancelCallback  cancel,
int  flags 
) throws com.foxit.sdk.PDFException

Constructor, for a PDF document.

User can set a valid SearchCancelCallback object in order to decide whether to cancel the searching process or not when the callback function in SearchCancelCallback is triggered.

Parameters
[in]documentA valid PDF document object.
[in]cancelA SearchCancelCallback object which decides if the searching process needs to be canceled when the callback function is triggered. This can be null which means not to cancel the searching process. If this is not null, it should be a valid SearchCancelCallback object implemented by user. Default value: null.
[in]flagsParsing flags used for parsing text during searching. Please refer to values starting from com.foxit.sdk.pdf.TextPage.e_ParseTextNormal and this can be one or combination of these values.

◆ TextSearch() [2/5]

com.foxit.sdk.pdf.TextSearch.TextSearch ( XFADoc  xfa_document,
SearchCancelCallback  cancel 
) throws com.foxit.sdk.PDFException

Constructor, for a specified XFA document.

Parameters
[in]xfa_documentA valid XFA document object. It should have been loaded by function addon.xfa.XFADoc.startLoad .
[in]cancelA SearchCancelCallback object which decides if the searching process needs to be canceled when the callback function is triggered. This can be null which means not to cancel the searching process. If this is not null, it should be a valid SearchCancelCallback object implemented by user. Default value: null.

◆ TextSearch() [3/5]

com.foxit.sdk.pdf.TextSearch.TextSearch ( TextPage  text_page) throws com.foxit.sdk.PDFException

Constructor, for a specified text page.

Parameters
[in]text_pageA text page object.

◆ TextSearch() [4/5]

com.foxit.sdk.pdf.TextSearch.TextSearch ( Annot  annot) throws com.foxit.sdk.PDFException

Constructor, for a specified PDF annotation.

Currently, only support to search in appearance of following annotation types: freetext annotation, stamp annotation, widget annotation, and line annotation.

Parameters
[in]annotA valid annotation object.

◆ TextSearch() [5/5]

com.foxit.sdk.pdf.TextSearch.TextSearch ( TextSearch  other)

Constructor, with another text search object.

Parameters
[in]otherAnother text search object.

Member Function Documentation

◆ delete()

synchronized void com.foxit.sdk.pdf.TextSearch.delete ( )

Clean up related resources immediately.

Returns
None.
Note
Once this function is called, current object cannot be used anymore.

Reimplemented from com.foxit.sdk.common.Base.

◆ findNext()

boolean com.foxit.sdk.pdf.TextSearch.findNext ( ) throws com.foxit.sdk.PDFException

Search for next matched pattern.

Returns
true means the next match is found, while false means no next match can be found or any other error.

◆ findPrev()

boolean com.foxit.sdk.pdf.TextSearch.findPrev ( ) throws com.foxit.sdk.PDFException

Search for previous matched pattern.

Returns
true means the previous match is found, while false means no previous match can be found or any other error.

◆ getMatchEndCharIndex()

int com.foxit.sdk.pdf.TextSearch.getMatchEndCharIndex ( ) throws com.foxit.sdk.PDFException

Get the index of the last character of current match pattern, based on current match page.

Returns
The index of the last character, in current match page, starting from 0. -1 means no matched sentence is found.

◆ getMatchPageIndex()

int com.foxit.sdk.pdf.TextSearch.getMatchPageIndex ( ) throws com.foxit.sdk.PDFException

Get the page index, to which current match belongs.

This function can only be used for a text search in PDF document or in XFA document.

Returns
The index of the page, which contains the current match, starting from 0. -1 means not matched pattern has been found.

◆ getMatchRects()

RectFArray com.foxit.sdk.pdf.TextSearch.getMatchRects ( ) throws com.foxit.sdk.PDFException

Get the rectangles of current match pattern.

Returns
An array of rectangles.

◆ getMatchSentence()

String com.foxit.sdk.pdf.TextSearch.getMatchSentence ( ) throws com.foxit.sdk.PDFException

Get the sentence that contains current match pattern.

Returns
The sentence content, which contains current match.

◆ getMatchSentenceEndIndex()

int com.foxit.sdk.pdf.TextSearch.getMatchSentenceEndIndex ( ) throws com.foxit.sdk.PDFException

Get the index of the last character of current matched pattern, based on the matched sentence.

In a sentence, there may be more than 2 matched patterns. This function, along with function , can help to confirm which pattern in the sentence is just current matched pattern.

Returns
The index of the last character of current matched pattern, based on the match sentence, starting from 0. -1 means no matched sentence is found.

◆ getMatchSentenceStartIndex()

int com.foxit.sdk.pdf.TextSearch.getMatchSentenceStartIndex ( ) throws com.foxit.sdk.PDFException

Get the index of the first character of current matched pattern, based on the matched sentence.

In a sentence, there may be more than 2 matched patterns. This function, along with function , can help to confirm which pattern in the sentence is just current matched pattern.

Returns
The index of the first character of current matched pattern, based on the matched sentence, starting from 0. -1 means no matched sentence is found.

◆ getMatchStartCharIndex()

int com.foxit.sdk.pdf.TextSearch.getMatchStartCharIndex ( ) throws com.foxit.sdk.PDFException

Get the index of the first character of current match pattern, based on current match page.

Returns
The index of the first character, in current match page, starting from 0. -1 means no matched sentence is found.

◆ isEmpty()

boolean com.foxit.sdk.pdf.TextSearch.isEmpty ( )

Check whether current object is empty or not.

When the current object is empty, that means current object is useless.

Returns
true means current object is empty, while false means not.

◆ setEndPage()

boolean com.foxit.sdk.pdf.TextSearch.setEndPage ( int  page_index) throws com.foxit.sdk.PDFException

Set ending page index.

This function can only be used for a text search object which is constructed with PDFDoc object or com.foxit.sdk.addon.xfa.XFADoc object. For other case, this function will throw exception com.foxit.sdk.common.Constants.e_ErrUnsupported .
If this function is not called, default value count-1 will be used as the ending page index.

Parameters
[in]page_indexIndex of the page, from which the search ended. Valid range: from 0 to (count-1). count is returned by function PDFDoc.getPageCount for PDF document or by function addon.xfa.XFADoc.getPageCount for XFA document.
Returns
true means success, while false means failure.

◆ setPattern()

boolean com.foxit.sdk.pdf.TextSearch.setPattern ( String  key_words) throws com.foxit.sdk.PDFException

Set keywords to search.

Parameters
[in]key_wordsThe text content to be searched. It should not be an empty string.
Returns
true means success, while false means failure.

◆ setSearchFlags()

boolean com.foxit.sdk.pdf.TextSearch.setSearchFlags ( int  search_flags) throws com.foxit.sdk.PDFException

Set search flags.

If this function is not called, default value com.foxit.sdk.pdf.TextSearch.e_SearchNormal will be used.

Parameters
[in]search_flagsSearch flags. Please refer to values starting from com.foxit.sdk.pdf.TextSearch.e_SearchNormal and this can be one or combination of these values.
Returns
true means success, while false means failure.

◆ setStartCharacter()

boolean com.foxit.sdk.pdf.TextSearch.setStartCharacter ( int  char_index) throws com.foxit.sdk.PDFException

Set starting character index, from where the search process is to be started.

This function can only be used for a text search object which is constructed with TextPage object or PDFDoc object. For other case, this function will throw exception com.foxit.sdk.common.Constants.e_ErrUnsupported .
If this function is not called for a newly constructed text serach object, default value will be used as the starting character index:

  • 0 will be used as the starting character index for first search started by functionTextSearch.findNext .
  • (count-1) will be used as the starting character index for first search by function TextSearch.findPrev .


Parameters
[in]char_indexStarting character index, from where the search process is to be started. Valid range: from 0 to (count-1). count means the count of characters in the starting page for search process.
Returns
true means success, while false means failure.

◆ setStartPage()

boolean com.foxit.sdk.pdf.TextSearch.setStartPage ( int  page_index) throws com.foxit.sdk.PDFException

Set starting page index.

This function can only be used for a text search object which is constructed with PDFDoc object or com.foxit.sdk.addon.xfa.XFADoc object. For other case, this function will throw exception com.foxit.sdk.common.Constants.e_ErrUnsupported .
If this function is not called, default value 0 will be used as the starting page index.

Parameters
[in]page_indexIndex of the page, from which the search starts. Valid range: from 0 to (count-1). count is returned by function PDFDoc.getPageCount for PDF document or by function addon.xfa.XFADoc.getPageCount for XFA document.
Returns
true means success, while false means failure.