Skip to main content

DevExpress v25.1 Update — Your Feedback Matters

Our What's New in v25.1 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

Organize Annotations in PDF Document API

  • 7 minutes to read

The PDF Document API supports the following annotation types:

Link Annotations
A hypertext link to a URI or a destination (a reference to a page with specific view parameters).
Markup Annotations

Annotations used to mark up document content. The following markups are available:

  • Text Markup (text highlight, underline, strikeout)
  • Sticky Note
  • Caret
  • Rubber Stamp
  • Shape (circle, square)
  • File Attachment
  • Free Text (text box, callout, typewriter)
  • Ink
  • Path (line, polyline, polygon)
Redaction Annotations
Tools used to remove sensitive or confidential information from a document. These annotations allow users to mark areas of text, images, or other content for redaction.

You can create, delete, and flatten annotations, edit their content, and add related comments and reviews.

The PdfPageFacade.Annotations property retrieves all page annotation properties. Use the PdfDocumentFacade.Pages property to obtain the PdfPageFacade instance.

This topic describes the following features common to all annotation types:

Refer to the corresponding topic from the table below for more detailed information on the required annotation type.

Annotation Type Base Class More Information
Link Annotation PdfLinkAnnotationFacade Links in PDF Documents
File Attachment Annotations PdfFileAttachmentAnnotationFacade Attach Files to a PDF
Markup Annotations PdfMarkupAnnotationFacade Manage Markup Annotations
Redaction Annotations PdfRedactAnnotationFacade Manage Redaction

#Edit Annotations

The PdfPageFacade.Annotations property returns all page annotation properties. You can filter annotation properties, cast them to the corresponding class, and use class properties to modify annotation parameters.

The code sample below changes annotations created in the previous example, so they appear as follows:

markup edited

using DevExpress.Pdf;
using System.Linq;

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Result.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Obtain all free text annotations
    var freeTextAnnotations = pageFacade.Annotations.Where
        (annotation => annotation.Type == PdfAnnotationType.FreeText);
    foreach (PdfFreeTextAnnotationFacade freeText in freeTextAnnotations) 
    { 
        // Change border parameters and text justification
        freeText.InteriorColor = new PdfRGBColor(0.36, 0.54, 0.66);
        freeText.BorderWidth = 0.5;
        freeText.TextJustification = PdfTextJustification.Centered;
    }

    // Retrieve all circle annotations
    var circleAnnotations = pageFacade.Annotations.Where
        (annotation => annotation.Type == PdfAnnotationType.Circle);
    foreach (PdfCircleAnnotationFacade pdfCircle in circleAnnotations)
    { 
        // Change border style and color
        pdfCircle.BorderStyle = PdfBorderStyle.Dash; 
        pdfCircle.Color = new PdfRGBColor(0.52, 0.87, 0.01);
    }

    // Get all rubber stamps 
    var rubberStampAnnotations = pageFacade.Annotations.Where
        (annotation => annotation.Type == PdfAnnotationType.RubberStamp);
    foreach (PdfRubberStampAnnotationFacade pdfRubberStamp in rubberStampAnnotations)
    {
        // Generate a stamp from another document’s page
        pdfRubberStamp.SetCustomIcon("..\\..\\Demo.pdf", 4);
    }

    // Obtain all file attachments
    var fileAttachments = pageFacade.Annotations.Where
        (annotation => annotation.Type == PdfAnnotationType.FileAttachment);
    foreach (PdfFileAttachmentAnnotationFacade fileAttachment in fileAttachments) 
    {
        // Change the icon and its color
        fileAttachment.Color = new PdfRGBColor(0.83, 0.13, 0.18);
        fileAttachment.IconName = PdfFileAttachmentAnnotationIconName.Tag;
    }
        // Save the result
        processor.SaveDocument("..\\..\\Result_1.pdf");
}

#Add Comments to Annotations

Use API from the table below to add comments to markup annotations:

API Description
PdfMarkupAnnotationFacade.AddReply Adds a comment to the annotation. This method returns the PdfMarkupAnnotationComment object. Use this class’ members to change the reply’s author, subject and text.
PdfMarkupAnnotationFacade.Replies Obtains all annotation comments.
PdfMarkupAnnotationComment.AddReply Creates a nested comment.
PdfMarkupAnnotationComment.Replies Gets all nested comments added to the comment.
PdfMarkupAnnotationComment.AddReview Adds a review to the comment. Use the PdfMarkupAnnotationFacade.Reviews property to get all reviews.

The code sample below adds two nested comments to all sticky notes (the document in opened in WinForms PDF Viewer):

added comments

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

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Retrieve all text annotations
    var stickyNotes = pageFacade.Annotations.Where
            (annotation => annotation.Type == PdfAnnotationType.Text);
    foreach (PdfTextAnnotationFacade stickyNote in stickyNotes)
    {
        // Add comments
        AddAnnotationComments(stickyNote);
    }

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

private static void AddAnnotationComments(PdfMarkupAnnotationFacade annotation)
{
    PdfMarkupAnnotationComment comment =
       annotation.AddReply("Reviewer", "Done");
    comment.Subject = "Proofread";

    PdfMarkupAnnotationComment nestedComment =
       comment.AddReply(annotation.Author, "Thanks");
    nestedComment.Subject = "Reviewed";
}

#Add Reviews to Annotations

Call the PdfMarkupAnnotationFacade.AddReview method to add a review to the markup annotation. The PdfMarkupAnnotationFacade.Reviews property obtains all annotation reviews.

To remove all reviews, call the PdfMarkupAnnotationFacade.ClearReviews() method.

The code sample below adds a review to the annotations from a specific author (the document is opened in the WinForms PDF Viewer):

added reviews

using DevExpress.Pdf;

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

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    foreach(PdfMarkupAnnotationFacade markupAnnotation in pageFacade.Annotations)
    {

        // Check the annotation author
        if (markupAnnotation.Author == "Brian Zetc") 
        {

          // Add a review to the annotation
            markupAnnotation.AddReview("Cardle Anita W", PdfAnnotationReviewStatus.Accepted);
        }
    }
    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}

#Flatten Annotations

Call one of the following methods to flatten an annotation:

Method Description
PdfDocumentFacade.FlattenAnnotations Flattens document annotations.
PdfPageFacade.FlattenAnnotations Flattens annotations of a specific page.
PdfAnnotationFacade.Flatten() Flattens a specific annotation.

Note

When you call one of the Flatten… methods for redaction annotations, their overlay parameters (text, fill color, and so on) are not applied and redacted content is not removed. Use one of the ApplyRedactAnnotations methods to apply these annotations.

The code sample below flattens all text annotations in the document:

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

  // Flatten all text annotations:
  PdfDocumentFacade documentFacade = processor.DocumentFacade;
  documentFacade.FlattenAnnotations(PdfAnnotationType.Text);

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

#Remove Annotations

Call the PdfAnnotationFacade.Remove() method to remove an annotation.

The code sample below removes all annotations from a specific author:

using DevExpress.Pdf;
using System.Linq;

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

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Retrieve all markup annotations
    var markups = pageFacade.Annotations.Where
            (annotation => annotation.Type != PdfAnnotationType.Link).ToList();
    foreach(PdfMarkupAnnotationFacade markupAnnotation in markups)
    {
        // Check the annotation author
        if (markupAnnotation.Author == "Brian Zetc")
        {
            // Remove the annotation
            markupAnnotation.Remove();
        }
    }
    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}