VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging.Pdf.Wpf.UI Namespace / WpfPdfTextSelectionTool Class
Members Example



In This Topic
    WpfPdfTextSelectionTool Class
    In This Topic
    Visual tool that allows to navigate and select text on PDF page.
    Object Model
    WpfPdfTextSelectionTool ClassIObjectClipboard InterfaceCopyItemUIAction ClassPdfPage ClassDeselectAllItemsUIAction ClassWpfImageViewer ClassSelectAllItemsUIAction ClassPdfTextRegion ClassPdfTextRegionFormatter Class
    Syntax
    'Declaration
     
    Public Class WpfPdfTextSelectionTool 
       Inherits WpfPdfVisualTool
       Implements Vintasoft.Imaging.UIActions.ISupportUIActions 
    public class WpfPdfTextSelectionTool : WpfPdfVisualTool, Vintasoft.Imaging.UIActions.ISupportUIActions  
    public __gc class WpfPdfTextSelectionTool : public WpfPdfVisualTool, Vintasoft.Imaging.UIActions.ISupportUIActions  
    public ref class WpfPdfTextSelectionTool : public WpfPdfVisualTool, Vintasoft.Imaging.UIActions.ISupportUIActions  
    Example
    This example shows how to search text in PDF document loaded into WPF image viewer.
    Public Partial Class FormWithWpfPdfTextSelectionTool
        Inherits System.Windows.Window
        '...
        Private _imageViewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewer = Nothing
        Private _textSelectionTool As Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfTextSelectionTool = Nothing
                
        '...
        Public Sub New()
            '...
            ' creates the PdfTextSelectionTool instance
            _textSelectionTool = New Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfTextSelectionTool(New System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(56, 0, 0, 255)))
            ' subscribe to text selection tool events
            AddHandler _textSelectionTool.SelectionChanged, New System.EventHandler(AddressOf _pdfViewerTool_SelectionChanged)
            AddHandler _textSelectionTool.LinkClick, New System.EventHandler(Of Vintasoft.Imaging.Pdf.Wpf.UI.PdfLinkEventArgs)(AddressOf _pdfViewerTool_LinkClick)
            ' sets the PDF text selection tool as current tool
            _imageViewer.VisualTool = _textSelectionTool
        End Sub
                
        '  Occurs when the _viewerTool.Selection is changed.
        Private Sub _pdfViewerTool_SelectionChanged(sender As Object, e As System.EventArgs)
            If _textSelectionTool.SelectedRegion IsNot Nothing Then
                ' show selected text
                System.Windows.MessageBox.Show(_textSelectionTool.SelectedRegion.TextContent)
            End If
        End Sub
                
        ' Occurs when the link is clicked. 
        Private Sub _pdfViewerTool_LinkClick(sender As Object, e As Vintasoft.Imaging.Pdf.Wpf.UI.PdfLinkEventArgs)
            Select Case e.Action.ActionType
                Case Vintasoft.Imaging.Pdf.Tree.PdfActionType.[GoTo]
                    ' go to a destination in the current document
                    _imageViewer.FocusedIndex = e.DestinationImageIndex
                    Exit Select
                Case Vintasoft.Imaging.Pdf.Tree.PdfActionType.Launch
                    ' launch an application
                    System.Diagnostics.Process.Start(DirectCast(e.Action, Vintasoft.Imaging.Pdf.Tree.PdfLaunchAction).WinCommandLine)
                    Exit Select
                Case Vintasoft.Imaging.Pdf.Tree.PdfActionType.URI
                    ' resolve a uniform resource identifier (URI)
                    System.Diagnostics.Process.Start(DirectCast(e.Action, Vintasoft.Imaging.Pdf.Tree.PdfUriAction).URI)
                    Exit Select
            End Select
        End Sub
    End Class
    public partial class FormWithWpfPdfTextSelectionTool : System.Windows.Window
    {
        //...
        Vintasoft.Imaging.Wpf.UI.WpfImageViewer _imageViewer = null;
        Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfTextSelectionTool _textSelectionTool = null;
                
        //...
        public FormWithWpfPdfTextSelectionTool()
        {            
            //...
            // creates the PdfTextSelectionTool instance
            _textSelectionTool = new Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfTextSelectionTool(
                new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(56, 0, 0, 255)));
            // subscribe to text selection tool events
            _textSelectionTool.SelectionChanged += new System.EventHandler(_pdfViewerTool_SelectionChanged);
            _textSelectionTool.LinkClick += 
                new System.EventHandler<Vintasoft.Imaging.Pdf.Wpf.UI.PdfLinkEventArgs>(_pdfViewerTool_LinkClick);
            // sets the PDF text selection tool as current tool
            _imageViewer.VisualTool = _textSelectionTool;
        }
                
        //  Occurs when the _viewerTool.Selection is changed.
        private void _pdfViewerTool_SelectionChanged(object sender, System.EventArgs e)
        {
            if (_textSelectionTool.SelectedRegion != null)
                // show selected text
                System.Windows.MessageBox.Show(_textSelectionTool.SelectedRegion.TextContent);
        }
                
        // Occurs when the link is clicked. 
        void _pdfViewerTool_LinkClick(object sender, Vintasoft.Imaging.Pdf.Wpf.UI.PdfLinkEventArgs e)
        {
            switch (e.Action.ActionType)
            {
                case Vintasoft.Imaging.Pdf.Tree.PdfActionType.GoTo:
                    // go to a destination in the current document
                    _imageViewer.FocusedIndex = e.DestinationImageIndex;
                    break;
                case Vintasoft.Imaging.Pdf.Tree.PdfActionType.Launch:
                    // launch an application
                    System.Diagnostics.Process.Start(((Vintasoft.Imaging.Pdf.Tree.PdfLaunchAction)e.Action).WinCommandLine);
                    break;
                case Vintasoft.Imaging.Pdf.Tree.PdfActionType.URI:
                    // resolve a uniform resource identifier (URI)
                    System.Diagnostics.Process.Start(((Vintasoft.Imaging.Pdf.Tree.PdfUriAction)e.Action).URI);
                    break;
            }
        }
    }
    Inheritance Hierarchy

    System.Object
       System.Windows.Threading.DispatcherObject
          System.Windows.DependencyObject
             System.Windows.Media.Visual
                System.Windows.UIElement
                   System.Windows.FrameworkElement
                      System.Windows.Controls.Control
                         System.Windows.Controls.ContentControl
                            Vintasoft.Imaging.Wpf.UI.VisualTools.WpfVisualTool
                               Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfVisualTool
                                  Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfTextSelectionTool

    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also