Back to Devexpress

PdfTextMarkupAnnotationData Class

officefileapi-devexpress-dot-pdf-17b2d276.md

latest11.0 KB
Original Source

PdfTextMarkupAnnotationData Class

Represents a text markup annotation.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public class PdfTextMarkupAnnotationData :
    PdfMarkupAnnotationData
vb
Public Class PdfTextMarkupAnnotationData
    Inherits PdfMarkupAnnotationData

The following members return PdfTextMarkupAnnotationData objects:

Remarks

Create a Text Markup Annotation

Call the PdfDocumentProcessor.AddTextMarkupAnnotation method to create a text markup annotation at the specified page area. If the target area does not contain text, the annotation is not created.

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

csharp
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");
}
vb
Imports DevExpress.Pdf
'...
Using processor As New PdfDocumentProcessor()

    'Load a document:
    processor.LoadDocument("..\..\Document.pdf")

    'Add a text markup annotation on the first page:
    Dim textMarkup As PdfTextMarkupAnnotationData =
    processor.AddTextMarkupAnnotation(1, New PdfRectangle(90, 100, 240, 230), 
    PdfTextMarkupAnnotationType.Highlight)

    If textMarkup IsNot Nothing Then
        'Specify the annotation properties:
        textMarkup.Author = "Bill Smith"
        textMarkup.Contents = "Important!"
        textMarkup.Color = New PdfRGBColor(0.8, 0.2, 0.1)
    End If

    'Add a sticky note at the first page:
    Dim textAnnotation As PdfTextAnnotationData =
    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")
End Using

Access Text Markup Annotations

The PdfDocumentProcessor.GetMarkupAnnotationData method allows you to retrieve all annotations located at the specified page. Use the PdfMarkupAnnotationDataExtensions.AsTextMarkupAnnotation method to obtain text markup annotation. The returned PdfTextMarkupAnnotationData object allows you to change the annotation settings.

The code sample below changes the markup style for annotations made by a specific author and changes the icon for all text annotations:

csharp
using DevExpress.Pdf;
using System;
using System.Collections.Generic;
//...
private static void EditAnnotations(PdfDocumentProcessor processor)
{
    //Retrieve annotations made by the specified author:
    var textMarkups =
        processor.GetMarkupAnnotationData(1).
        Where(annotation => annotation.Author.Contains("Cardle Anita L"));
    foreach (PdfMarkupAnnotationData markup in textMarkups)
    {
        //Get all text markup annotations from the retrieved list:
        PdfTextMarkupAnnotationData pdfTextMarkup =
         markup.AsTextMarkupAnnotation();
        if (pdfTextMarkup != null)
            //Change the annotation's markup type:
            pdfTextMarkup.MarkupType = PdfTextMarkupAnnotationType.Squiggly;
    }

    var annotations = processor.GetMarkupAnnotationData(1);
    foreach (PdfMarkupAnnotationData annotation in annotations)
    {
        //Get all text annotations:
        PdfTextAnnotationData textAnnotation = annotation.AsTextAnnotation();
        if (textAnnotation != null)

            //Change the annotation icon:
            textAnnotation.IconName = PdfTextAnnotationIconName.Note;
    }
}
vb
Imports DevExpress.Pdf
Imports System
Imports System.Collections.Generic
'...

Private Shared Sub EditAnnotations(ByVal processor As PdfDocumentProcessor)
    'Retrieve annotations made by the specified author:
    Dim textMarkups = processor.GetMarkupAnnotationData(1).Where(Function(annotation) annotation.Author.Contains("Cardle Anita L"))
    For Each markup As PdfMarkupAnnotationData In textMarkups
        'Get all text markup annotations from the retrieved list:
        Dim pdfTextMarkup As PdfTextMarkupAnnotationData = markup.AsTextMarkupAnnotation()
        If pdfTextMarkup IsNot Nothing Then
            'Change the annotation's markup type:
            pdfTextMarkup.MarkupType = PdfTextMarkupAnnotationType.Squiggly
        End If
    Next markup

    Dim annotations = processor.GetMarkupAnnotationData(1)
    For Each annotation As PdfMarkupAnnotationData In annotations
        'Get all text annotations:
        Dim textAnnotation As PdfTextAnnotationData = annotation.AsTextAnnotation()
        If textAnnotation IsNot Nothing Then

            'Change the annotation icon:
            textAnnotation.IconName = PdfTextAnnotationIconName.Note
        End If
    Next annotation
End Sub

Delete Text Markup 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.

csharp
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")));
    }
}
vb
Imports DevExpress.Pdf
Imports System.Linq
'...
Private Shared Sub DeleteAnnotations(ByVal processor As PdfDocumentProcessor)
    For i As Integer = 0 To processor.Document.Pages.Count
        'Remove Borman Aaron Lewis's markup annotations from a page.
        processor.DeleteMarkupAnnotations(processor.GetMarkupAnnotationData(i).Where(Function(annotation) annotation.Author.Contains("Borman Aaron Lewis")))
    Next i
End Sub

Inheritance

Object PdfAnnotationData PdfMarkupAnnotationData PdfTextMarkupAnnotationData

Extension Methods

AsTextAnnotation()

AsTextMarkupAnnotation()

See Also

PdfTextMarkupAnnotationData Members

DevExpress.Pdf Namespace