How to: Specify the Text Markup Annotation Properties When the Annotation is being Created

  • 2 minutes to read

This example demonstrates how to specify the text markup annotation properties when the annotation is being created in a document.

To add a markup to text:

  • Select the text;
  • Right-click the text and choose Highlight, Strikethrough or Underline item in the invoked context menu.

    MarkupContextMenu

When the text markup annotation is being created in a document, the PdfViewer.TextMarkupAnnotationCreating event is raised. In this event, you can specify the annotation properties (for example, the default color used to underline a text using the PdfTextMarkupAnnotationCreatingEventArgs.Color property as shown in the code below).

You can see properties applied to a newly created annotation in the Annotation Properties dialog.

To open this dialog, right-click the annotation and choose the Properties… item in the context menu.

ClickAnnotationPropertiesItem

The Annotation Properties dialog is shown below.

AnnotationPropertiesExampleResult

The following code shows how to handle the PdfViewer.TextMarkupAnnotationCreating event.

using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraPdfViewer;

namespace SpecifyAnnotationProperties {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();

            // Load a document.
            pdfViewer1.LoadDocument("..\\..\\Demo.pdf");

            // Handle the TextMarkupAnnotationCreating event to specify the text markup annotation properties when the annotation is being created. 
            pdfViewer1.TextMarkupAnnotationCreating += pdfViewer1_TextMarkupAnnotationCreating;
        }

        private void pdfViewer1_TextMarkupAnnotationCreating(object sender, PdfTextMarkupAnnotationCreatingEventArgs e) {
            e.Author = "John Smith";
            e.Comment = "Note.";
            e.Color = Color.Gold;
        }
    }
}