RadPDFViewer

2 posts, 0 answers
  1. FirstName
    FirstName avatar
    4 posts
    Member since:
    Sep 2017

    Posted 31 Oct Link to this post

    Hello, is it possible to force PDfViwer select only the whole words, but not the parts of them ? Thanks in advance
  2. Deyan
    Admin
    Deyan avatar
    158 posts

    Posted 03 Nov Link to this post

    Hello,

    RadPdfViewer does not have out-of-the-box selection mode which selects only full words. However, it provides some public API which may help you achieve this scenario. The following code snippet shows sample implementation which uses TextSelection SelectionChanged event and TextPosition MoveToCurrentWordStart and MoveToCurrentWordEnd methods.
    private void PdfViewer_DocumentChanged(object sender, Telerik.Windows.Documents.Fixed.DocumentChangedEventArgs e)
    {
        if (e.OldDocument != null)
        {
            e.OldDocument.Selection.SelectionChanged -= this.Selection_SelectionChanged;
        }
     
        if(e.NewDocument != null)
        {
            e.NewDocument.Selection.SelectionChanged += this.Selection_SelectionChanged;
        }
    }
     
    private void Selection_SelectionChanged(object sender, EventArgs e)
    {
        TextSelection selection = (TextSelection)sender;
     
        if (selection.StartPosition != null)
        {
            selection.StartPosition.MoveToCurrentWordStart();
        }
     
        if (selection.EndPosition != null)
        {
            selection.EndPosition.MoveToCurrentWordEnd();
        }
    }

    In order to test the above implementation, you should subscribe to RadPdfViewer instance DocumentChanged event. This may be done right after InitializeComponent() method call in the MainWindow constructor as shown in the snippet below:
    this.pdfViewer.DocumentChanged += this.PdfViewer_DocumentChanged;

    I hope this is helpful.

    Regards,
    Deyan
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top