VintaSoft Imaging .NET SDK 10.1
Vintasoft.Imaging.Pdf.Wpf.UI Namespace / WpfPdfTextMarkupTool Class
Members Example



In This Topic
    WpfPdfTextMarkupTool Class
    In This Topic
    Visual tool that allows to markup (highlight, strikeout, underline, squiggly underline) text using Vintasoft.Imaging.Pdf.Tree.Annotations.PdfTextMarkupAnnotation on PDF page.
    Object Model
    WpfPdfTextMarkupTool ClassWpfImageViewer ClassPdfTextMarkupAnnotationAppearanceGenerator ClassWpfTextSelectionTool Class
    Syntax
    'Declaration
     
    <DefaultPropertyAttribute("Content")>
    <ContentPropertyAttribute("Content")>
    <LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)>
    <StyleTypedPropertyAttribute(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)>
    <XmlLangPropertyAttribute("Language")>
    <UsableDuringInitializationAttribute(True)>
    <RuntimeNamePropertyAttribute("Name")>
    <UidPropertyAttribute("Uid")>
    <TypeDescriptionProviderAttribute(MS.Internal.ComponentModel.DependencyObjectProvider)>
    <NameScopePropertyAttribute("NameScope", System.Windows.NameScope)>
    Public Class WpfPdfTextMarkupTool 
       Inherits Vintasoft.Imaging.Wpf.UI.VisualTools.WpfVisualTool
    [DefaultProperty("Content")]
    [ContentProperty("Content")]
    [Localizability(LocalizationCategory.None, Readability=Readability.Unreadable)]
    [StyleTypedProperty(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)]
    [XmlLangProperty("Language")]
    [UsableDuringInitialization(true)]
    [RuntimeNameProperty("Name")]
    [UidProperty("Uid")]
    [TypeDescriptionProvider(MS.Internal.ComponentModel.DependencyObjectProvider)]
    [NameScopeProperty("NameScope", System.Windows.NameScope)]
    public class WpfPdfTextMarkupTool : Vintasoft.Imaging.Wpf.UI.VisualTools.WpfVisualTool 
    [DefaultProperty("Content")]
    [ContentProperty("Content")]
    [Localizability(LocalizationCategory.None, Readability=Readability.Unreadable)]
    [StyleTypedProperty(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)]
    [XmlLangProperty("Language")]
    [UsableDuringInitialization(true)]
    [RuntimeNameProperty("Name")]
    [UidProperty("Uid")]
    [TypeDescriptionProvider(MS.Internal.ComponentModel.DependencyObjectProvider)]
    [NameScopeProperty("NameScope", System.Windows.NameScope)]
    public __gc class WpfPdfTextMarkupTool : public Vintasoft.Imaging.Wpf.UI.VisualTools.WpfVisualTool 
    [DefaultProperty("Content")]
    [ContentProperty("Content")]
    [Localizability(LocalizationCategory.None, Readability=Readability.Unreadable)]
    [StyleTypedProperty(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)]
    [XmlLangProperty("Language")]
    [UsableDuringInitialization(true)]
    [RuntimeNameProperty("Name")]
    [UidProperty("Uid")]
    [TypeDescriptionProvider(MS.Internal.ComponentModel.DependencyObjectProvider)]
    [NameScopeProperty("NameScope", System.Windows.NameScope)]
    public ref class WpfPdfTextMarkupTool : public Vintasoft.Imaging.Wpf.UI.VisualTools.WpfVisualTool 
    Remarks
    Example
    This example shows how to use PDF Text Markup tool to highlight text on PDF page.
    ''' <summary>
    ''' Sets the WpfPdfTextMarkupTool as current tool of specified image viewer.
    ''' </summary>
    ''' <param name="imageViewer">The image viewer.</param>
    Public Shared Sub SetPdfTextMarkupTool(imageViewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewer)
        ' create an instance of the PdfTextMarkupTool class
        Dim textMarkupTool As New Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfTextMarkupTool()
                
        ' set text markup mode to "Highlight"
        textMarkupTool.MarkupMode = Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfTextMarkupToolMode.Highlight
                
        ' set color of markup annotation to "Orange"
        textMarkupTool.HighlightColor = System.Windows.Media.Colors.Orange
                
        ' subscribe to the MarkupAnnotationCreated event
        AddHandler textMarkupTool.MarkupAnnotationCreated, AddressOf TextMarkupTool_MarkupAnnotationCreated
                
        ' get TextSelectionTool from image viewer
        Dim textSelectionTool As Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool = GetTextSelectionTool(imageViewer)
                
        ' set the PdfTextMarkupTool+TextSelectionTool as visual tool of the image viewer
        imageViewer.VisualTool = New Vintasoft.Imaging.Wpf.UI.VisualTools.WpfCompositeVisualTool(textMarkupTool, textSelectionTool)
    End Sub
                
    ''' <summary>
    ''' Returns the text selection tool for specified image viewer.
    ''' </summary>
    ''' <param name="imageViewer">The image viewer.</param>
    ''' <returns>The text selection tool.</returns>
    Private Shared Function GetTextSelectionTool(imageViewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewer) As Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool
        ' search a TextSelectionTool in visual tools of the image viewer
        Dim textSelectionTool As Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool = Vintasoft.Imaging.Wpf.UI.VisualTools.WpfVisualTool.FindVisualTool(Of Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool)(imageViewer.VisualTool)
        If textSelectionTool IsNot Nothing Then
            Return textSelectionTool
        End If
                
        ' create an instance of text selection tool
        Return New Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool()
    End Function
                
    ''' <summary>
    ''' Handles the MarkupAnnotationCreated event of the PdfTextMarkupTool visual tool.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="Vintasoft.Imaging.Pdf.UI.PdfMarkupAnnotationEventArgs" /> instance containing the event data.</param>
    Private Shared Sub TextMarkupTool_MarkupAnnotationCreated(sender As Object, e As Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfMarkupAnnotationEventArgs)
        ' set user name as title of text markup annotation
        e.MarkupAnnotation.Title = System.Environment.UserName
    End Sub
    /// <summary>
    /// Sets the WpfPdfTextMarkupTool as current tool of specified image viewer.
    /// </summary>
    /// <param name="imageViewer">The image viewer.</param>
    public static void SetPdfTextMarkupTool(Vintasoft.Imaging.Wpf.UI.WpfImageViewer imageViewer)
    {
        // create an instance of the PdfTextMarkupTool class
        Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfTextMarkupTool textMarkupTool = new Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfTextMarkupTool();
                
        // set text markup mode to "Highlight"
        textMarkupTool.MarkupMode = Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfTextMarkupToolMode.Highlight;
                
        // set color of markup annotation to "Orange"
        textMarkupTool.HighlightColor = System.Windows.Media.Colors.Orange;
                
        // subscribe to the MarkupAnnotationCreated event
        textMarkupTool.MarkupAnnotationCreated += TextMarkupTool_MarkupAnnotationCreated;
                
        // get TextSelectionTool from image viewer
        Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool textSelectionTool = GetTextSelectionTool(imageViewer);
                
        // set the PdfTextMarkupTool+TextSelectionTool as visual tool of the image viewer
        imageViewer.VisualTool = new Vintasoft.Imaging.Wpf.UI.VisualTools.WpfCompositeVisualTool(textMarkupTool, textSelectionTool);
    }
                
    /// <summary>
    /// Returns the text selection tool for specified image viewer.
    /// </summary>
    /// <param name="imageViewer">The image viewer.</param>
    /// <returns>The text selection tool.</returns>
    private static Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool GetTextSelectionTool(Vintasoft.Imaging.Wpf.UI.WpfImageViewer imageViewer)
    {
        // search a TextSelectionTool in visual tools of the image viewer
        Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool textSelectionTool =
            Vintasoft.Imaging.Wpf.UI.VisualTools.WpfVisualTool.FindVisualTool<Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool>(imageViewer.VisualTool);
        if (textSelectionTool != null)
            return textSelectionTool;
                
        // create an instance of text selection tool
        return new Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool();
    }
                
    /// <summary>
    /// Handles the MarkupAnnotationCreated event of the PdfTextMarkupTool visual tool.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="Vintasoft.Imaging.Pdf.UI.PdfMarkupAnnotationEventArgs" /> instance containing the event data.</param>
    private static void TextMarkupTool_MarkupAnnotationCreated(object sender, Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfMarkupAnnotationEventArgs e)
    {
        // set user name as title of text markup annotation
        e.MarkupAnnotation.Title = System.Environment.UserName;
    }
    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.WpfPdfTextMarkupTool

    Requirements

    Target Platforms: .NET 6; .NET 5; .NET Core 3.1; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also