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

RadPDFViewer

2 Answers 139 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
FirstName
Top achievements
Rank 1
FirstName asked on 31 Oct 2017, 08:24 PM
Hello, is it possible to force PDfViwer select only the whole words, but not the parts of them ? Thanks in advance

2 Answers, 1 is accepted

Sort by
0
Accepted
Deyan
Telerik team
answered on 03 Nov 2017, 05:16 PM
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.
0
FirstName
Top achievements
Rank 1
answered on 19 Dec 2017, 09:47 AM
Yep, thanks a lot, Deyan.
Tags
PDFViewer
Asked by
FirstName
Top achievements
Rank 1
Answers by
Deyan
Telerik team
FirstName
Top achievements
Rank 1
Share this question
or