Foxit PDF SDK
foxit::pdf::TextSearch类 参考
类 foxit::pdf::TextSearch 继承关系图:
foxit::Base

Public 类型

enum  SearchFlags {
  e_SearchNormal = 0x00, e_SearchMatchCase = 0x01, e_SearchMatchWholeWord = 0x02, e_SearchConsecutive = 0x04,
  e_SearchNotMatchFullWidth = 0x20
}
 搜索标志的枚举。 更多...
 

Public 成员函数

 TextSearch (const PDFDoc &document, SearchCancelCallback *cancel=0, int flags=foxit::pdf::TextPage::e_ParseTextNormal)
 对于PDF文档的构造函数。 更多...
 
 TextSearch (const foxit::addon::xfa::XFADoc &xfa_document, foxit::pdf::SearchCancelCallback *cancel=0)
 对于指定XFA文档的构造函数。 更多...
 
 TextSearch (const foxit::pdf::TextPage &text_page)
 对于指定文本页面的构造函数。 更多...
 
 TextSearch (const foxit::pdf::annots::Annot &annot)
 对于指定PDF注释的构造函数。 更多...
 
 TextSearch (const TextSearch &other)
 用另一个文本搜索对象的构造函数。 更多...
 
 ~TextSearch ()
 析构函数。
 
bool FindNext ()
 搜索下一个匹配的模式。 更多...
 
bool FindPrev ()
 搜索上一个匹配的模式。 更多...
 
int GetMatchEndCharIndex () const
 基于当前匹配页面,获取当前匹配模式最后一个字符的索引。 更多...
 
int GetMatchPageIndex () const
 获取当前匹配所属的页面索引。 更多...
 
RectFArray GetMatchRects () const
 获取当前匹配模式的矩形。 更多...
 
WString GetMatchSentence ()
 获取包含当前匹配模式的句子。 更多...
 
int GetMatchSentenceEndIndex ()
 基于匹配句子,获取当前匹配模式最后一个字符的索引。 更多...
 
int GetMatchSentenceStartIndex ()
 基于匹配句子,获取当前匹配模式第一个字符的索引。 更多...
 
int GetMatchStartCharIndex () const
 基于当前匹配页面,获取当前匹配模式第一个字符的索引。 更多...
 
bool IsEmpty () const
 检查当前对象是否为空。 更多...
 
bool operator != (const TextSearch &other) const
 不等于操作符。 更多...
 
TextSearchoperator= (const TextSearch &other)
 赋值操作符。 更多...
 
bool operator== (const TextSearch &other) const
 等于操作符。 更多...
 
bool SetEndPage (int page_index)
 设置结束页面索引。 更多...
 
bool SetPattern (const wchar_t *key_words, bool is_regex_search=false)
 设置要搜索的关键词。 更多...
 
bool SetSearchFlags (uint32 search_flags)
 设置搜索标志。 更多...
 
bool SetStartCharacter (int char_index)
 设置起始字符索引,搜索过程从该位置开始。 更多...
 
bool SetStartPage (int page_index)
 设置起始页面索引。 更多...
 
- Public 成员函数 继承自 foxit::Base
FS_HANDLE Handle () const
 获取当前对象的句柄。 更多...
 

详细描述

此类可以在PDF文档/XFA文档/文本页面或PDF注释的外观中构造文本搜索。 它提供进行文本搜索和获取搜索结果的函数:

成员枚举类型说明

◆ SearchFlags

搜索标志的枚举。

此枚举的值可以单独使用或组合使用。

枚举值
e_SearchNormal 

无特殊搜索选项。

e_SearchMatchCase 

如果设置,搜索时匹配关键字的大小写。

e_SearchMatchWholeWord 

如果设置,搜索时匹配关键字的完整单词。

e_SearchConsecutive 

如果设置,搜索时连续匹配关键字。例如,"CC"在"CCC"中将被匹配两次。

e_SearchNotMatchFullWidth 

如果设置,在搜索期间忽略全角字符并将所有字符视为标准ASCII或标准宽度字符。

构造及析构函数说明

◆ TextSearch() [1/5]

foxit::pdf::TextSearch::TextSearch ( const PDFDoc document,
SearchCancelCallback cancel = 0,
int  flags = foxit::pdf::TextPage::e_ParseTextNormal 
)
explicit

对于PDF文档的构造函数。

用户可以设置有效的 SearchCancelCallback 对象,以便在触发 SearchCancelCallback中的回调函数时决定是否取消搜索过程。

参数
[in]document有效的PDF文档对象。
[in]cancelSearchCancelCallback 对象,决定在触发回调函数时 是否需要取消搜索过程。这可以是 NULL,表示不取消搜索过程。 如果不是 NULL,应该是用户实现的有效 SearchCancelCallback 对象。默认值:NULL
[in]flags搜索期间用于解析文本的解析标志。请参考从 TextPage::e_ParseTextNormal 开始的值,这可以是这些值中的一个或组合。
默认值:TextPage::e_ParseTextNormal

◆ TextSearch() [2/5]

foxit::pdf::TextSearch::TextSearch ( const foxit::addon::xfa::XFADoc xfa_document,
foxit::pdf::SearchCancelCallback cancel = 0 
)
explicit

对于指定XFA文档的构造函数。

参数
[in]xfa_document有效的XFA文档对象。它应该已经通过 函数 addon::xfa::XFADoc::StartLoad 加载。
[in]cancelSearchCancelCallback 对象,决定在触发回调函数时 是否需要取消搜索过程。这可以是 NULL, 表示不取消搜索过程。如果不是 NULL, 应该是用户实现的有效 SearchCancelCallback 对象。 默认值:NULL

◆ TextSearch() [3/5]

foxit::pdf::TextSearch::TextSearch ( const foxit::pdf::TextPage text_page)
explicit

对于指定文本页面的构造函数。

参数
[in]text_page文本页面对象。

◆ TextSearch() [4/5]

foxit::pdf::TextSearch::TextSearch ( const foxit::pdf::annots::Annot annot)
explicit

对于指定PDF注释的构造函数。

目前,仅支持在以下注释类型的外观中搜索: 自由文本注释、印章注释、小部件注释和线条注释。

参数
[in]annot有效的注释对象。

◆ TextSearch() [5/5]

foxit::pdf::TextSearch::TextSearch ( const TextSearch other)

用另一个文本搜索对象的构造函数。

参数
[in]other另一个文本搜索对象。

成员函数说明

◆ FindNext()

bool foxit::pdf::TextSearch::FindNext ( )

搜索下一个匹配的模式。

返回
true 表示找到下一个匹配,false 表示找不到下一个匹配或 发生其他错误。

◆ FindPrev()

bool foxit::pdf::TextSearch::FindPrev ( )

搜索上一个匹配的模式。

返回
true 表示找到上一个匹配,false 表示找不到上一个匹配或 发生其他错误。

◆ GetMatchEndCharIndex()

int foxit::pdf::TextSearch::GetMatchEndCharIndex ( ) const

基于当前匹配页面,获取当前匹配模式最后一个字符的索引。

返回
当前匹配页面中最后一个字符的索引,从0开始。 -1表示未找到匹配的句子。

◆ GetMatchPageIndex()

int foxit::pdf::TextSearch::GetMatchPageIndex ( ) const

获取当前匹配所属的页面索引。

此函数只能用于PDF文档或XFA文档中的文本搜索。

返回
包含当前匹配的页面索引,从0开始。 -1表示未找到匹配的模式。

◆ GetMatchRects()

RectFArray foxit::pdf::TextSearch::GetMatchRects ( ) const

获取当前匹配模式的矩形。

返回
矩形数组。

◆ GetMatchSentence()

WString foxit::pdf::TextSearch::GetMatchSentence ( )

获取包含当前匹配模式的句子。

返回
包含当前匹配的句子内容。

◆ GetMatchSentenceEndIndex()

int foxit::pdf::TextSearch::GetMatchSentenceEndIndex ( )

基于匹配句子,获取当前匹配模式最后一个字符的索引。

在一个句子中,可能有超过2个匹配模式。此函数与函数 GetMatchSentenceStartIndex 一起, 可以帮助确认句子中的哪个模式就是当前匹配的模式。

返回
基于匹配句子的当前匹配模式最后一个字符的索引,从0开始。 -1表示未找到匹配的句子。

◆ GetMatchSentenceStartIndex()

int foxit::pdf::TextSearch::GetMatchSentenceStartIndex ( )

基于匹配句子,获取当前匹配模式第一个字符的索引。

在一个句子中,可能有超过2个匹配模式。此函数与函数 GetMatchSentenceEndIndex 一起, 可以帮助确认句子中的哪个模式就是当前匹配的模式。

返回
基于匹配句子的当前匹配模式第一个字符的索引,从0开始。 -1表示未找到匹配的句子。

◆ GetMatchStartCharIndex()

int foxit::pdf::TextSearch::GetMatchStartCharIndex ( ) const

基于当前匹配页面,获取当前匹配模式第一个字符的索引。

返回
当前匹配页面中第一个字符的索引,从0开始。 -1表示未找到匹配的句子。

◆ IsEmpty()

bool foxit::pdf::TextSearch::IsEmpty ( ) const

检查当前对象是否为空。

当前对象为空时,意味着当前对象无用。

返回
true 表示当前对象为空,false 表示不为空。

◆ operator !=()

bool foxit::pdf::TextSearch::operator != ( const TextSearch other) const

不等于操作符。

参数
[in]other另一个文本搜索对象。此函数将检查当前对象是否不等于这个对象。
返回
true 表示不相等,false 表示相等。

◆ operator=()

TextSearch& foxit::pdf::TextSearch::operator= ( const TextSearch other)

赋值操作符。

参数
[in]other另一个文本搜索对象,其值将被赋给当前对象。
返回
对当前对象自身的引用。

◆ operator==()

bool foxit::pdf::TextSearch::operator== ( const TextSearch other) const

等于操作符。

参数
[in]other另一个文本搜索对象。此函数将检查当前对象是否等于这个对象。
返回
true 表示相等,false 表示不相等。

◆ SetEndPage()

bool foxit::pdf::TextSearch::SetEndPage ( int  page_index)

设置结束页面索引。

此函数只能用于使用 PDFDoc 对象或 addon::xfa::XFADoc 对象 构造的文本搜索对象。对于其他情况,此函数将抛出异常 foxit::e_ErrUnsupported
如果不调用此函数,默认值count-1将用作结束页面索引。

参数
[in]page_index搜索结束的页面索引。 有效范围:从0到(count-1)。count 由函数 PDFDoc::GetPageCount (对于PDF文档)或函数 addon::xfa::XFADoc::GetPageCount (对于XFA文档)返回。
返回
true 表示成功,false 表示失败。

◆ SetPattern()

bool foxit::pdf::TextSearch::SetPattern ( const wchar_t *  key_words,
bool  is_regex_search = false 
)

设置要搜索的关键词。

参数
[in]key_words要搜索的文本内容。它不应是空字符串。
[in]is_regex_searchtrue 表示启用正则表达式搜索,false 表示不启用。 如果启用正则表达式搜索,函数 TextSearch::SetSearchFlags 设置的搜索标志将被忽略。默认值:false
返回
true 表示成功,false 表示失败。

◆ SetSearchFlags()

bool foxit::pdf::TextSearch::SetSearchFlags ( uint32  search_flags)

设置搜索标志。

如果不调用此函数,将使用默认值 TextSearch::e_SearchNormal

参数
[in]search_flags搜索标志。请参考从 TextSearch::e_SearchNormal 开始的值, 这可以是这些值中的一个或组合。
返回
true 表示成功,false 表示失败。

◆ SetStartCharacter()

bool foxit::pdf::TextSearch::SetStartCharacter ( int  char_index)

设置起始字符索引,搜索过程从该位置开始。

此函数只能用于使用 TextPage 对象或 PDFDoc 对象 构造的文本搜索对象。对于其他情况,此函数将抛出异常 foxit::e_ErrUnsupported
如果不为新构造的文本搜索对象调用此函数, 将使用默认值作为起始字符索引:

  • 对于由函数 TextSearch::FindNext 开始的第一次搜索, 将使用0作为起始字符索引。
  • 对于由函数 TextSearch::FindPrev 开始的第一次搜索, 将使用(count-1)作为起始字符索引。
参数
[in]char_index搜索过程开始的起始字符索引。 有效范围:从0到(count-1)。count 表示搜索过程起始页面中的字符数量。
返回
true 表示成功,false 表示失败。

◆ SetStartPage()

bool foxit::pdf::TextSearch::SetStartPage ( int  page_index)

设置起始页面索引。

此函数只能用于使用 PDFDoc 对象或 addon::xfa::XFADoc 对象 构造的文本搜索对象。对于其他情况,此函数将抛出异常 foxit::e_ErrUnsupported
如果不调用此函数,默认值0将用作起始页面索引。

参数
[in]page_index搜索开始的页面索引。 有效范围:从0到(count-1)。count 由函数 PDFDoc::GetPageCount (对于PDF文档)或函数 addon::xfa::XFADoc::GetPageCount (对于XFA文档)返回。
返回
true 表示成功,false 表示失败。