VintaSoft Imaging .NET SDK 15.2: Documentation for .NET developer
Vintasoft.Imaging.Pdf.Wpf.UI Namespace / WpfPdfTextMarkupTool Class
Members Object Syntax Remarks Example Hierarchy Requirements SeeAlso
In This Topic
WpfPdfTextMarkupTool Class
In This Topic
Visual tool that allows to markup (highlight, strikeout, underline, squiggly underline) text using PdfTextMarkupAnnotation on PDF page.
Object Model
PdfTextMarkupAnnotationAppearanceGenerator WpfTextSelectionTool WpfImageViewer WpfPdfTextMarkupTool
Syntax
'Declaration

<ToolboxItemAttribute("ToolboxItemType = null", "ToolboxItemTypeName = ")>
<DesignTimeVisibleAttribute("Visible = False")>
<DefaultPropertyAttribute("Content")>
<ContentPropertyAttribute("Content")>
<LocalizabilityAttribute(None)>
<StyleTypedPropertyAttribute("Property = FocusVisualStyle", "StyleTargetType = System.Windows.Controls.Control")>
<XmlLangPropertyAttribute("Name = Language")>
<UsableDuringInitializationAttribute("Usable = True")>
<RuntimeNamePropertyAttribute("Name = Name")>
<UidPropertyAttribute()>
<TypeDescriptionProviderAttribute("TypeName = MS.Internal.ComponentModel.DependencyObjectProvider")>
<NameScopePropertyAttribute("Name = NameScope", "Type = System.Windows.NameScope")>
Public Class WpfPdfTextMarkupTool
   Inherits Vintasoft.Imaging.Wpf.UI.VisualTools.WpfVisualTool

[ToolboxItem("ToolboxItemType = null", "ToolboxItemTypeName = ")]
[DesignTimeVisible("Visible = False")]
[DefaultProperty("Content")]
[ContentProperty("Content")]
[Localizability(None)]
[StyleTypedProperty("Property = FocusVisualStyle", "StyleTargetType = System.Windows.Controls.Control")]
[XmlLangProperty("Name = Language")]
[UsableDuringInitialization("Usable = True")]
[RuntimeNameProperty("Name = Name")]
[UidProperty()]
[TypeDescriptionProvider("TypeName = MS.Internal.ComponentModel.DependencyObjectProvider")]
[NameScopeProperty("Name = NameScope", "Type = System.Windows.NameScope")]
public class WpfPdfTextMarkupTool : Vintasoft.Imaging.Wpf.UI.VisualTools.WpfVisualTool

Remarks

This visual tool requires WpfTextSelectionTool, i.e. image viewer must use WpfCompositeVisualTool that contains WpfTextSelectionTool and WpfPdfTextMarkupTool.

Example

This C#/VB.NET code 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>
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>
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 11; .NET 10; .NET 9; .NET 8; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

See Also