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