Completed
Last Updated: 04 Jan 2017 15:01 by ADMIN
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 18 Nov 2015 14:22
Category: PdfViewer
Type: Feature Request
0
ADD. RadPdfViewerNavigator - when you perform searching, the user should be notified by a message if no matches are found
Note: If you use the next button to navigate to the next search result, the user should be notified when the end of the document is reached as well.

Workaround:

public Form1()
{
    InitializeComponent(); 
    this.radPdfViewer1.LoadDocument(@"..\..\..\samplePdf.pdf"); 

    //create a new button
    CommandBarButton findNext = new CommandBarButton();
    findNext.Text = PdfViewerLocalizationProvider.CurrentProvider.GetLocalizedString(PdfViewerStringId.NavigatorFindNextButton);
    findNext.Click += findNext_Click;
    findNext.Image = this.radPdfViewerNavigator1.FindNextButton.Image;
    //hide the currently available button
    this.radPdfViewerNavigator1.DefaultStrip.Items.Add(findNext);
    this.radPdfViewerNavigator1.FindNextButton.Visibility = ElementVisibility.Collapsed;
}

private void findNext_Click(object sender, EventArgs e)
{
    if (this.radPdfViewerNavigator1.SearchTextBox.Text != string.Empty)
    { 
        if (this.radPdfViewerNavigator1.AssociatedViewer == null || this.radPdfViewerNavigator1.AssociatedViewer.Document == null)
        {
            return;
        }

        PropertyInfo internalDocumentPI = typeof(RadFixedDocument).GetProperty("InternalDocument", BindingFlags.NonPublic | BindingFlags.Instance);
        object internalDocument = internalDocumentPI.GetValue(this.radPdfViewerNavigator1.AssociatedViewer.Document, null);
        object textSearch = internalDocument.GetType().GetProperty("TextSearch", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(internalDocument, null);
        MethodInfo mi = textSearch.GetType().GetMethod("Find", BindingFlags.Public | BindingFlags.Instance);
        TextSearchOptions searchOptions = new TextSearchOptions(false);
        SearchResult searchResult = mi.Invoke(textSearch, new object[2] { this.radPdfViewerNavigator1.SearchTextBox.Text, searchOptions }) as SearchResult;
        if (searchResult.Result != null)
        {
            this.radPdfViewerNavigator1.AssociatedViewer.Select(searchResult);
        }
        else
        {
            RadMessageBox.Show("No matches");
        }
    }
}
0 comments