GroupDocs.Parser provides the functionality to extract a highlight (a part of the text which is usually used to explain the context of the found text in the search functionality) from documents by the GetHighlight method:
The position parameter defines the start position from which the highlight is extracted. The isDirect parameter indicates whether highlight extraction is direct: true if the highlight is extracted by the right of the position; otherwise, false. HighlightOptions parameter is used to define the end of the highlight.
// Highlight is limited to maxLength text length.HighlightOptions(intmaxLength);// Highlight is limited to the start (or the end) of a text line (or maxLength text length - if set).HighlightOptions(int?maxLength,boolisLineLimited);// Highlight is limited to word count (or maxLength text length - if set).HighlightOptions(int?maxLength,intwordCount);// General constructorHighlightOptions(int?maxLength,int?wordCount,boolisLineLimited);
The following example shows how to extract a highlight that contains 3 words:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Extract a highlight:HighlightItemhl=parser.GetHighlight(2,true,newHighlightOptions(3));// Check if highlight extraction is supportedif(hl==null){Console.WriteLine("Highlight extraction isn't supported");return;}// Print an extracted highlightConsole.WriteLine(string.Format("At {0}: {1}",hl.Position,hl.Text));}
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples:
Along with full featured .NET library we provide simple, but powerful free Apps.
You are welcome to parse documents and extract data from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Parser App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.