This sample shows how to add text markup annotations (highlight, strikeout, underline) to your PDF document.

Use PdfPage.AddHighlightAnnotation method to highlight and annotate a page area. This methods return an instance of the created annotation.

Alternatively, use PdfPage.AddStrikeoutAnnotation, PdfPage.AddJaggedUnderlineAnnotation and PdfPage.AddUnderlineAnnotation methods to strike out or underline a page area.

You can also modify new or existing text markup annotations. Cast corresponding widgets to PdfTextMarkupAnnotation class. Then call SetTextBounds() method or change Contents and Color properties of PdfTextMarkupAnnotation class.

C#
using System.Diagnostics;

using BitMiracle.Docotic.Pdf;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class TextMarkupAnnotations
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "TextMarkupAnnotations.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfPage page = pdf.Pages[0];
                PdfCanvas canvas = page.Canvas;

                // Draw text on the page
                const string Text = "Highlighted text";
                PdfPoint textPosition = new PdfPoint(10, 50);
                canvas.FontSize = 30;
                canvas.DrawString(textPosition, Text);

                // Get size of the drawn text
                PdfSize size = canvas.MeasureText(Text);
                var bounds = new PdfRectangle(textPosition, size);

                // Highlight and annotate the text
                var color = new PdfRgbColor(0, 0, 255);
                const string AnnotationContents = "Lorem ipsum";
                page.AddHighlightAnnotation(AnnotationContents, bounds, color);

                // Or call these method to strike out or underline the text:
                // page.AddStrikeoutAnnotation(AnnotationContents, bounds, color);
                // page.AddJaggedUnderlineAnnotation(AnnotationContents, bounds, color);
                // page.AddUnderlineAnnotation(AnnotationContents, bounds, color);

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
    }
}
VB
Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class TextMarkupAnnotations
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.

            Dim pathToFile As String = "TextMarkupAnnotations.pdf"

            Using pdf As New PdfDocument()
                Dim page As PdfPage = pdf.Pages(0)
                Dim canvas As PdfCanvas = page.Canvas

                ' Draw text on the page
                Const Text As String = "Highlighted text"
                Dim textPosition As New PdfPoint(10, 50)
                canvas.FontSize = 30
                canvas.DrawString(textPosition, Text)

                ' Get size of the drawn text
                Dim size As PdfSize = canvas.MeasureText(Text)
                Dim bounds = New PdfRectangle(textPosition, size)

                ' Highlight and annotate the text
                Dim color = New PdfRgbColor(0, 0, 255)
                Const AnnotationContents As String = "Lorem ipsum"
                page.AddHighlightAnnotation(AnnotationContents, bounds, color)

                ' Or call these method to strike out or underline the text:
                ' page.AddStrikeoutAnnotation(AnnotationContents, bounds, color);
                ' page.AddJaggedUnderlineAnnotation(AnnotationContents, bounds, color);
                ' page.AddUnderlineAnnotation(AnnotationContents, bounds, color);

                pdf.Save(pathToFile)
            End Using

            Process.Start(pathToFile)
        End Sub
    End Class
End Namespace