HighlightItem class

HighlightItem class

Represents a highlight, a part of the text which is usually used to explain the context of the found text in the search functionality.

An instance of HighlightItem is used as the return value of Parser.get_highlight (int, bool, HighlightOptions) method, and of the SearchResult.left_highlight_item and SearchResult.right_highlight_item properties. See the usage examples there.

The HighlightItem type exposes the following members:

Properties

Property Description
position The zero-based index of the start position of the highlight in the document text.
text The text of the highlight.

Example

from groupdocs.parser import Parser
from groupdocs.parser.options import HighlightOptions

with Parser("./sample.pdf") as parser:
    options = HighlightOptions(20)  # extract 20 characters around the highlight
    highlight = parser.get_highlight(100, True, options)
    if highlight is not None:
        print(f"Position: {highlight.position}")
        print(f"Text: {highlight.text}")

See Also