Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

PdfTextAnnotationData Class

Represents a text annotation.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v24.2.Core.dll

NuGet Package: DevExpress.Pdf.Core

#Declaration

public class PdfTextAnnotationData :
    PdfMarkupAnnotationData

#Remarks

#Create a Text Annotation

Call the PdfDocumentProcessor.AddTextAnnotation method to create a text annotation at the specified page area.

The code sample below highlights text with blue and adds a sticky note at the page corner.

image

using DevExpress.Pdf;
//...
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    //Load a document:
    processor.LoadDocument("..\\..\\Document.pdf");

    //Add a text markup annotation at the first page:
    PdfTextMarkupAnnotationData textMarkup =
    processor.AddTextMarkupAnnotation(1, new PdfRectangle(90, 100, 240, 230),
    PdfTextMarkupAnnotationType.Highlight);

    if (textMarkup != null)
    {
        //Specify the annotation properties:
        textMarkup.Author = "Bill Smith";
        textMarkup.Contents = "Important!";
        textMarkup.Color = new PdfRGBColor(0.8, 0.2, 0.1);
    }

    //Add a sticky note at the first page:
    PdfTextAnnotationData textAnnotation =
    processor.AddTextAnnotation(1, new PdfPoint(100, 300));

    //Specify the annotation parameters:
    textAnnotation.Author = "Nancy Davolio";
    textAnnotation.Checked = true;
    textAnnotation.Color = new PdfRGBColor(0.8, 0.2, 0.1);
    textAnnotation.Contents = "Please proofread this document";
    textAnnotation.IconName = PdfTextAnnotationIconName.Check;

    //Save the result:
    processor.SaveDocument("..\\..\\Result.pdf");
}

#Access Text Annotations

The PdfDocumentProcessor.GetMarkupAnnotationData method allows you to retrieve all annotations located at the specified page. Use the PdfMarkupAnnotationDataExtensions.AsTextAnnotation method to get text annotations.

The code sample below gets all annotations and adds a review to the first annotation:

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    processor.LoadDocument("..\\..\\Document.pdf");

    var annotations = processor.GetMarkupAnnotationData(1);
    annotations[0].AddReview("Borman Aaron Lewis", PdfAnnotationReviewStatus.Completed);
}

#Delete Text Annotations

Call the PdfDocumentProcessor.DeleteMarkupAnnotations method to remove all markup annotations from the specified page.

To delete a specific annotation, call the PdfDocumentProcessor.DeleteMarkupAnnotation method. Pass the target PdfMarkupAnnotationData object as a parameter to this method.

This example shows how to delete text markup annotations created by a specific author.

using DevExpress.Pdf;
using System.Linq;
//...
private static void DeleteAnnotations(PdfDocumentProcessor processor)
{
    for (int i = 0; i <= processor.Document.Pages.Count; i++)
    {
        //Remove Borman Aaron Lewis's markup annotations from a page.
        processor.DeleteMarkupAnnotations(processor.GetMarkupAnnotationData(i)
        .Where(annotation => annotation.Author.Contains("Borman Aaron Lewis")));
    }
}

#Inheritance

See Also