Free Support Forum - groupdocs.com

Highlight Text in Document without using Search


#1

Hi,
I would like to know if we can highlight text in currently viewed document in GroupDocs viewer without using search tool in toolbar. If possible please let me know how i can achieve it.


#2

Hello,

In GroupDocs.Viewer version 2.x you can perform a searching using browser only (pressing Ctrl+F in browser). So you don’t need GroupDpocs.Viewer’s scripts, fuctions and anything else. The only thing that is required is HTML-based rendering mode: when using this mode GroupDpocs.Viewer renders parsed text from document as text, not as images.

In order to enable this mode (it is disabled by default) you need to call a “UseHtmlBasedEngine()” method in .NET version and “useHtmlBasedEngine(true)” in Java version of Viewer.

If you will have more questions please feel free to contact us.


#3

Hi Denis.
Thank you for your quick reply.
The scenario in what i require is i perform search from the collection of files. when the list is retrieved, I would like to show preview of a file with searched keywords highlighted in it. Is this possible ?
For eg. I am searching file with content “details”, I get file “abc.doc” in output results. So when I preview file “abc.doc”, I should be able to highlight “details” keyword in it wherever it is present in doc file.


#4

Hello,

Thanks for getting back to us.
Yes, GroupDocs.Viewer can handle the scenario that you described. After finding a document where a keyword is found (“abc.doc” in your case) and displaying it client-side using GroupDocs.Viewer, you can highlight the target keyword. In order to do this you should invoke GroupDocs.Viewer’s search method when page loading is completed.
When DOM forming is completed ($(document).ready) you need to call a “searchForward” method as described below:


searchForward: search the document forward for the
specified value.

Parameters:

text
– a string to search for;

isCaseSensitive
– a Boolean value which specifies if the search is case-sensitive;

searchForSeparateWords

  • a Boolean value; if true, the Viewer will search for any of the words
    specified in the text parameter. If
    false, the Viewer control will search for exact matches of the whole phrase
    specified in the text parameter.

treatPhrasesInDoubleQuotesAsExact - a Boolean value; if true, then if a search
phrase is in double quotes, the Viewer will find a match only if words in the
current document are in the same order as they are in the search phrase and
each word is equal to each word of the search phrase. Whitespaces and separator
characters are ignored.

Example:

$(#searchTextInput).bind(“keypress”, function
(e) {

var code = e.keyCode || e.which;

if (code == 13) { //Enter
keycode


containerElement.groupdocsViewer(“searchForward”,
$(this).val(), false, true);

}

});

<o:p> </o:p>

$(#searchForwardButton).click(function () {


containerElement.groupdocsViewer(“searchForward”,
$(#searchTextInput).val());

});

There are also the “searchBackward” and “clearSearchValue” methods but in your scenario they are not applicable.

If you have more questions, please feel free to contact us.