Foxit PDF SDK

Instance Methods | List of all members
FSTextSearch Class Reference
Inheritance diagram for FSTextSearch:

## Instance Methods
(BOOL) | - findNext
| Search for next matched pattern. More...
(BOOL) | - findPrev
| Search for previous matched pattern. More...
(int) | - getMatchEndCharIndex
| Get the index of the last character of current match pattern, based on current match page. More...
(int) | - getMatchPageIndex
| Get the page index, to which current match belongs. More...
(FSRectFArray *) | - getMatchRects
| Get the rectangles of current match pattern. More...
(NSString *) | - getMatchSentence
| Get the sentence that contains current match pattern. More...
(int) | - getMatchSentenceEndIndex
| Get the index of the last character of current matched pattern, based on the matched sentence. More...
(int) | - getMatchSentenceStartIndex
| Get the index of the first character of current matched pattern, based on the matched sentence. More...
(int) | - getMatchStartCharIndex
| Get the index of the first character of current match pattern, based on current match page. More...
(id) | - initWithAnnot:
| Constructor, for a specified PDF annotation. More...
(id) | - initWithDocument:cancel:flags:
| Constructor, for a PDF document. More...
(id) | - initWithOther:
| Constructor, with another text search object. More...
(id) | - initWithText_page:
| Constructor, for a specified text page. More...
(id) | - initWithXfa_document:cancel:
| Constructor, for a specified XFA document. More...
(BOOL) | - isEmpty
| Check whether current object is empty or not. More...
(BOOL) | - setEndPage:
| Set ending page index. More...
(BOOL) | - setPattern:is_regex_search:
| Set keywords to search. More...
(BOOL) | - setSearchFlags:
| Set search flags. More...
(BOOL) | - setStartCharacter:
| Set starting character index, from where the search process is to be started. More...
(BOOL) | - setStartPage:
| Set starting page index. More...

## 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 FSTextSearch::setPattern:is_regex_search:, FSTextSearch::setStartPage:, FSTextSearch::setEndPage: and FSTextSearch::setSearchFlags:.
- To do the searching, use function FSTextSearch::findNext or FSTextSearch::findPrev.
- To get the searching result, use functions GetMatchXXX().

## Method Documentation

## ◆ findNext()

- (BOOL) findNext |  |  |

Search for next matched pattern.

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

## ◆ findPrev()

- (BOOL) findPrev |  |  |

Search for previous matched pattern.

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

## ◆ getMatchEndCharIndex()

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

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

- (FSRectFArray *) getMatchRects |  |  |

Get the rectangles of current match pattern.

Returns
  An array of rectangles.

## ◆ getMatchSentence()

- (NSString *) getMatchSentence |  |  |

Get the sentence that contains current match pattern.

Returns
  The sentence content, which contains current match.

## ◆ getMatchSentenceEndIndex()

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

## ◆ initWithAnnot:()

- (id) initWithAnnot: |  | (FSAnnot*) | 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.

## ◆ initWithDocument:cancel:flags:()

- (id) initWithDocument: |  | (FSPDFDoc*) | document
cancel: |  | (id<FSSearchCancelCallback>) | cancel
flags: |  | (int) | flags

Constructor, for a PDF document.

User can set a valid 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 object which decides if the searching process needs to be canceled when the callback function is triggered. This can be nil which means not to cancel the searching process. If this is not nil, it should be a valid object implemented by user. Default value: nil.
  [in] | flags | Parsing flags used for parsing text during searching. Please refer to values starting from FSTextPageParseTextNormal and this can be one or combination of these values. Default value: FSTextPageParseTextNormal.

## ◆ initWithOther:()

- (id) initWithOther: |  | (FSTextSearch*) | other |

Constructor, with another text search object.

Parameters

  [in] | other | Another text search object.

## ◆ initWithText_page:()

- (id) initWithText_page: |  | (FSTextPage*) | text_page |

Constructor, for a specified text page.

Parameters

  [in] | text_page | A text page object.

## ◆ initWithXfa_document:cancel:()

- (id) initWithXfa_document: |  | (FSXFADoc*) | xfa_document
cancel: |  | (id<FSSearchCancelCallback>) | cancel

Constructor, for a specified XFA document.

Parameters

  [in] | xfa_document | A valid XFA document object. It should have been loaded by function FSXFADoc::startLoad:.
  [in] | cancel | A object which decides if the searching process needs to be canceled when the callback function is triggered. This can be nil which means not to cancel the searching process. If this is not nil, it should be a valid object implemented by user. Default value: nil.

## ◆ isEmpty()

- (BOOL) isEmpty |  |  |

Check whether current object is empty or not.

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

Returns
  YES means current object is empty, while NO means not.

## ◆ setEndPage:()

- (BOOL) setEndPage: |  | (int) | page_index |

Set ending page index.

This function can only be used for a text search object which is constructed with FSPDFDoc object or FSXFADoc object. For other case, this function will throw exception FSErrUnsupported.
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 FSPDFDoc::getPageCount for PDF document or by function FSXFADoc::getPageCount for XFA document.

Returns
  YES means success, while NO means failure.

## ◆ setPattern:is_regex_search:()

- (BOOL) setPattern: |  | (NSString *) | key_words
is_regex_search: |  | (BOOL) | 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 | YES means to enable regular expression search, while NO means not. If regular expression search is enabled, the search flag set by function FSTextSearch::setSearchFlags: will be ignored. Default value: NO.

Returns
  YES means success, while NO means failure.

## ◆ setSearchFlags:()

- (BOOL) setSearchFlags: |  | (unsigned int) | search_flags |

Set search flags.

If this function is not called, default value FSTextSearchSearchNormal will be used.

Parameters

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

Returns
  YES means success, while NO means failure.

## ◆ setStartCharacter:()

- (BOOL) setStartCharacter: |  | (int) | 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 FSTextPage object or FSPDFDoc object. For other case, this function will throw exception FSErrUnsupported.
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 functionFSTextSearch::findNext.
- (count-1) will be used as the starting character index for first search by function FSTextSearch::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
  YES means success, while NO means failure.

## ◆ setStartPage:()

- (BOOL) setStartPage: |  | (int) | page_index |

Set starting page index.

This function can only be used for a text search object which is constructed with FSPDFDoc object or FSXFADoc object. For other case, this function will throw exception FSErrUnsupported.
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 FSPDFDoc::getPageCount for PDF document or by function FSXFADoc::getPageCount for XFA document.

Returns
  YES means success, while NO means failure.