Foxit PDF SDK

Public Member Functions | Static Public Attributes | List of all members
FSDK.TextSearch Class Reference

## Public Member Functions
| TextSearch (text_page)
| Constructor, for a specified text page. More...
| TextSearch (annot)
| Constructor, for a specified PDF annotation. More...
| constructor (document, cancel, flags)
| Constructor, for a PDF document. More...
| constructor (xfa_document, cancel)
| Constructor, for a specified XFA document. More...
| FindNext ()
| Search for next matched pattern. More...
| FindPrev ()
| Search for previous matched pattern. More...
| GetMatchEndCharIndex ()
| Get the index of the last character of current match pattern, based on current match page. More...
| GetMatchPageIndex ()
| Get the page index, to which current match belongs. More...
| GetMatchRects ()
| Get the rectangles of current match pattern. More...
| GetMatchSentence ()
| Get the sentence that contains current match pattern. More...
| GetMatchSentenceEndIndex ()
| Get the index of the last character of current matched pattern, based on the matched sentence. More...
| GetMatchSentenceStartIndex ()
| Get the index of the first character of current matched pattern, based on the matched sentence. More...
| GetMatchStartCharIndex ()
| Get the index of the first character of current match pattern, based on current match page. More...
| IsEmpty ()
| Check whether current object is empty or not. More...
| SetEndPage (page_index)
| Set ending page index. More...
| SetPattern (key_words, is_regex_search)
| Set keywords to search. More...
| SetSearchFlags (search_flags)
| Set search flags. More...
| SetStartCharacter (char_index)
| Set starting character index, from where the search process is to be started. More...
| SetStartPage (page_index)
| Set starting page index. More...

## Static Public Attributes
static | e_SearchConsecutive
| If set, match the key word consecutively when searching. For example, "CC" will be matched twice in "CCC".
static | e_SearchMatchCase
| If set, match the case of keyword when searching.
static | e_SearchMatchWholeWord
| If set, match the whole word of keyword when searching.
static | e_SearchNormal
| Enumeration for searching flags. More...
static | e_SearchNotMatchFullWidth
| 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:

- To specify the searching pattern and options, use functions FSDK.TextSearch.SetPattern, FSDK.TextSearch.SetStartPage, FSDK.TextSearch.SetEndPage and FSDK.TextSearch.SetSearchFlags.
- To do the searching, use function FSDK.TextSearch.FindNext or FSDK.TextSearch.FindPrev.
- To get the searching result, use functions GetMatchXXX().

## Constructor & Destructor Documentation

## ◆ TextSearch() [1/2]

FSDK.TextSearch.TextSearch | ( | text_page |  | ) |

Constructor, for a specified text page.

Parameters

  [in] | text_page | A text page object.

## ◆ TextSearch() [2/2]

FSDK.TextSearch.TextSearch | ( | annot |  | ) |

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] | annot | A valid annotation object.

## Member Function Documentation

## ◆ constructor() [1/2]

FSDK.TextSearch.constructor | ( | document | ,
|  | cancel | ,
|  | flags |
| ) |  |

Constructor, for a PDF document.

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

Parameters

  [in] | document | A valid PDF document object.
  [in] | cancel | A FSDK.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 FSDK.SearchCancelCallback object implemented by user. Default value: null.
  [in] | flags | Parsing flags used for parsing text during searching. Please refer to values starting from FSDK.TextPage.e_ParseTextNormal and this can be one or combination of these values. Default value: FSDK.TextPage.e_ParseTextNormal.

## ◆ constructor() [2/2]

FSDK.TextSearch.constructor | ( | xfa_document | ,
|  | cancel |
| ) |  |

Constructor, for a specified XFA document.

Parameters

  [in] | xfa_document | A valid XFA document object. It should have been loaded by function FSDK.XFADoc.StartLoad.
  [in] | cancel | A FSDK.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 FSDK.SearchCancelCallback object implemented by user. Default value: null.

## ◆ FindNext()

FSDK.TextSearch.FindNext | ( |  | ) |

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()

FSDK.TextSearch.FindPrev | ( |  | ) |

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()

FSDK.TextSearch.GetMatchEndCharIndex | ( |  | ) |

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()

FSDK.TextSearch.GetMatchPageIndex | ( |  | ) |

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()

FSDK.TextSearch.GetMatchRects | ( |  | ) |

Get the rectangles of current match pattern.

Returns
  An array of rectangles.

## ◆ GetMatchSentence()

FSDK.TextSearch.GetMatchSentence | ( |  | ) |

Get the sentence that contains current match pattern.

Returns
  The sentence content, which contains current match.

## ◆ GetMatchSentenceEndIndex()

FSDK.TextSearch.GetMatchSentenceEndIndex | ( |  | ) |

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 FSDK.GetMatchSentenceStartIndex, 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()

FSDK.TextSearch.GetMatchSentenceStartIndex | ( |  | ) |

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 FSDK.GetMatchSentenceEndIndex, 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()

FSDK.TextSearch.GetMatchStartCharIndex | ( |  | ) |

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()

FSDK.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()

FSDK.TextSearch.SetEndPage | ( | page_index |  | ) |

Set ending page index.

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

Parameters

  [in] | page_index | Index of the page, from which the search ended. Valid range: from 0 to (count-1). count is returned by function FSDK.PDFDoc.GetPageCount for PDF document or by function FSDK.XFADoc.GetPageCount for XFA document.

Returns
  true means success, while false means failure.

## ◆ SetPattern()

FSDK.TextSearch.SetPattern | ( | key_words | ,
|  | is_regex_search |
| ) |  |

Set keywords to search.

Parameters

  [in] | key_words | The text content to be searched. It should not be an empty string.
  [in] | is_regex_search | true means to enable regular expression search, while false means not. If regular expression search is enabled, the search flag set by function FSDK.TextSearch.SetSearchFlags will be ignored. Default value: false.

Returns
  true means success, while false means failure.

## ◆ SetSearchFlags()

FSDK.TextSearch.SetSearchFlags | ( | search_flags |  | ) |

Set search flags.

If this function is not called, default value FSDK.TextSearch.e_SearchNormal will be used.

Parameters

  [in] | search_flags | Search flags. Please refer to values starting from FSDK.TextSearch.e_SearchNormal and this can be one or combination of these values.

Returns
  true means success, while false means failure.

## ◆ SetStartCharacter()

FSDK.TextSearch.SetStartCharacter | ( | char_index |  | ) |

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 FSDK.TextPage object or FSDK.PDFDoc object. For other case, this function will throw exception FSDK.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 functionFSDK.TextSearch.FindNext.
- (count-1) will be used as the starting character index for first search by function FSDK.TextSearch.FindPrev.

Parameters

  [in] | char_index | Starting 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()

FSDK.TextSearch.SetStartPage | ( | page_index |  | ) |

Set starting page index.

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

Parameters

  [in] | page_index | Index of the page, from which the search starts. Valid range: from 0 to (count-1). count is returned by function FSDK.PDFDoc.GetPageCount for PDF document or by function FSDK.XFADoc.GetPageCount for XFA document.

Returns
  true means success, while false means failure.

## Member Data Documentation

## ◆ e_SearchNormal

FSDK.TextSearch.e_SearchNormal
| static

Enumeration for searching flags.

Values of this enumeration can be used alone or in combination.No special searching options.