In This Topic
Visual tool that allows to markup (highlight, strikeout, underline, squiggly underline) text using
PdfTextMarkupAnnotation on PDF page.
Object Model
Syntax
Remarks
This visual tool requires TextSelectionTool, i.e. image viewer must use CompositeVisualTool that contains TextSelectionTool and PdfTextMarkupTool.
Example
This C#/VB.NET code shows how to use PDF Text Markup tool to highlight text on PDF page.
''' <summary>
''' Sets the PdfTextMarkupTool as current tool of specified image viewer.
''' </summary>
''' <param name="imageViewer">The image viewer.</param>
Public Shared Sub SetPdfTextMarkupTool(imageViewer As Vintasoft.Imaging.UI.ImageViewer)
' create an instance of the PdfTextMarkupTool class
Dim textMarkupTool As New Vintasoft.Imaging.Pdf.UI.PdfTextMarkupTool()
' set text markup mode to "Highlight"
textMarkupTool.MarkupMode = Vintasoft.Imaging.Pdf.UI.PdfTextMarkupToolMode.Highlight
' set color of markup annotation to "Orange"
textMarkupTool.HighlightColor = System.Drawing.Color.Orange
' subscribe to the MarkupAnnotationCreated event
AddHandler textMarkupTool.MarkupAnnotationCreated, AddressOf TextMarkupTool_MarkupAnnotationCreated
' get TextSelectionTool from image viewer
Dim textSelectionTool As Vintasoft.Imaging.UI.VisualTools.TextSelectionTool = GetTextSelectionTool(imageViewer)
' set the PdfTextMarkupTool+TextSelectionTool as visual tool of the image viewer
imageViewer.VisualTool = New Vintasoft.Imaging.UI.VisualTools.CompositeVisualTool(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.UI.ImageViewer) As Vintasoft.Imaging.UI.VisualTools.TextSelectionTool
' search a TextSelectionTool in visual tools of the image viewer
Dim textSelectionTool As Vintasoft.Imaging.UI.VisualTools.TextSelectionTool = Vintasoft.Imaging.UI.VisualTools.VisualTool.FindVisualTool(Of Vintasoft.Imaging.UI.VisualTools.TextSelectionTool)(imageViewer.VisualTool)
If textSelectionTool IsNot Nothing Then
Return textSelectionTool
End If
' create an instance of text selection tool
Return New Vintasoft.Imaging.UI.VisualTools.TextSelectionTool()
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.UI.PdfMarkupAnnotationEventArgs)
' set user name as title of text markup annotation
e.MarkupAnnotation.Title = System.Environment.UserName
End Sub
/// <summary>
/// Sets the PdfTextMarkupTool as current tool of specified image viewer.
/// </summary>
/// <param name="imageViewer">The image viewer.</param>
public static void SetPdfTextMarkupTool(Vintasoft.Imaging.UI.ImageViewer imageViewer)
{
// create an instance of the PdfTextMarkupTool class
Vintasoft.Imaging.Pdf.UI.PdfTextMarkupTool textMarkupTool = new Vintasoft.Imaging.Pdf.UI.PdfTextMarkupTool();
// set text markup mode to "Highlight"
textMarkupTool.MarkupMode = Vintasoft.Imaging.Pdf.UI.PdfTextMarkupToolMode.Highlight;
// set color of markup annotation to "Orange"
textMarkupTool.HighlightColor = System.Drawing.Color.Orange;
// subscribe to the MarkupAnnotationCreated event
textMarkupTool.MarkupAnnotationCreated += TextMarkupTool_MarkupAnnotationCreated;
// get TextSelectionTool from image viewer
Vintasoft.Imaging.UI.VisualTools.TextSelectionTool textSelectionTool = GetTextSelectionTool(imageViewer);
// set the PdfTextMarkupTool+TextSelectionTool as visual tool of the image viewer
imageViewer.VisualTool = new Vintasoft.Imaging.UI.VisualTools.CompositeVisualTool(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.UI.VisualTools.TextSelectionTool GetTextSelectionTool(Vintasoft.Imaging.UI.ImageViewer imageViewer)
{
// search a TextSelectionTool in visual tools of the image viewer
Vintasoft.Imaging.UI.VisualTools.TextSelectionTool textSelectionTool =
Vintasoft.Imaging.UI.VisualTools.VisualTool.FindVisualTool<Vintasoft.Imaging.UI.VisualTools.TextSelectionTool>(imageViewer.VisualTool);
if (textSelectionTool != null)
return textSelectionTool;
// create an instance of text selection tool
return new Vintasoft.Imaging.UI.VisualTools.TextSelectionTool();
}
/// <summary>
/// Handles the MarkupAnnotationCreated event of the PdfTextMarkupTool visual tool.
/// </summary>
private static void TextMarkupTool_MarkupAnnotationCreated(object sender, Vintasoft.Imaging.Pdf.UI.PdfMarkupAnnotationEventArgs e)
{
// set user name as title of text markup annotation
e.MarkupAnnotation.Title = System.Environment.UserName;
}
Inheritance Hierarchy
System.Object
 Vintasoft.Imaging.UI.VisualTools.VisualTool
   Vintasoft.Imaging.Pdf.UI.PdfTextMarkupTool
Requirements
Target Platforms: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
See Also