This is a migrated thread and some comments may be shown as answers.

Highlighting Words and Making them Visible.

3 Answers 125 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 2
Aaron asked on 10 Nov 2015, 09:07 PM

Hi,

We store a bunch of PDFs in SQL Server, and have implemented a full-text search using a PDF iFilter.  The user enters a keyword or phrase, then gets a list of matching PDFs in a ListBox.  

When the user selects a PDF from the ListBox, we load the PDF document from the database and present it in a RadPdfViewer.

However, I want to highlight the first instance of the word or phrase they searched for.  I've hooked into the PdfViewer's OnDocumentChanged event, and the handler looks like this:

        private void PdfViewerOnDocumentChanged(object sender, DocumentChangedEventArgs documentChangedEventArgs)
        {
            if (SearchText.IsNullOrEmpty())
                return;
            
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(200);
            timer.Tick += (o, args) =>
            {
                var searchResult = this.PdfViewer.Find(SearchText);

                if (!searchResult.Range.IsEmpty)
                {
                    PdfViewer.Document.Selection.Clear();
                    PdfViewer.Select(searchResult.Range);
                    PdfViewer.Document.CaretPosition.MoveToPosition((searchResult.Range.EndPosition));                    
                }
                timer.Stop();
            };
            timer.Start();
        }

This works well most of the time.  However, the area I have on screen for the PdfViewer is smaller than 1 page, and once in a while the word I'm trying to highlight is out of the visible area on the page.  

Is there a method I can use to either always have the highlighted text be visible, or at least detect when the text is near the bottom of the page, and move everything up a bit when that is the case?

Thanks.

Aaron

3 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 13 Nov 2015, 11:17 AM
Hello Aaron,

Thank you for contacting us.

It seems that the issue you are facing is caused by using the DispatcherTimer instance. I have tested your code by removing this timer and the PdfViewer seems to be scrolling correctly to the selected text. Could you please try the following code to confirm that it is working as expected on your side as well:
PdfViewer.DocumentChanged += (s, e) =>
    {
        SearchResult searchResult = PdfViewer.Find(SearchText);
 
        if (searchResult != SearchResult.NotFound)
        {
            PdfViewer.Document.CaretPosition.MoveToPosition(searchResult.Range.StartPosition);
            PdfViewer.Select(searchResult.Range);
        }
    };

I hope this is helpful.

Regards,
Deyan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Aaron
Top achievements
Rank 2
answered on 13 Nov 2015, 05:45 PM

Thanks for the reply.

 I tried this code and it still didn't scroll.  It found and highlighted the text, but it was below the bottom of the screen (again, we can't fit an 8.5 x 11 inch page on one screen).

We are using version 2014.2.729.1050 at the office.  I'm not sure if that's the issue.  

Even so, I love getting rid of the dispatcher timer.  Thanks for that.

Aaron

0
Deyan
Telerik team
answered on 18 Nov 2015, 12:12 PM
Hello Aaron,

I have managed to reproduce the issue with the version you have mentioned. However, with the version from the latest official release (Q3 2015 SP1), RadPdfViewer scrolls correctly to the search result in DocumentChanged event handler.

Could you please try the latest version to confirm that everything is working as expected on your side as well?

I hope this helps.

Regards,
Deyan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
PDFViewer
Asked by
Aaron
Top achievements
Rank 2
Answers by
Deyan
Telerik team
Aaron
Top achievements
Rank 2
Share this question
or