How to: Create a Text Markup Annotation and Specify its Properties

  • 2 minutes to read

This example shows how to create a markup annotation that highlights a selected text. To create this annotation for a selected text, call one of the PdfViewerControl.HighlightSelectedText overload methods.

To specify the annotation properties when the markup annotation is being created, handle the PdfViewerControl.TextMarkupAnnotationCreating event.

using System.Windows;
using DevExpress.Pdf;
using DevExpress.Xpf.PdfViewer;

namespace MarkupAnnotations {

    public partial class MainWindow : Window {
        public MainWindow() {

            // Load a document.

            // Handle the TextMarkupAnnotationCreating event to specify the annotation properties.
            viewer.TextMarkupAnnotationCreating += Viewer_TextMarkupAnnotationCreating;


        private void Viewer_TextMarkupAnnotationCreating(DependencyObject d, PdfTextMarkupAnnotationCreatingEventArgs e) {
            e.Author = "John Smith";
            e.Comment = "Note.";
            e.Color = System.Windows.Media.Color.FromRgb(229, 214, 0);

        private void viewer_DocumentLoaded(object sender, RoutedEventArgs e) {

            // Select the document area where the markup annotation will be created.
            viewer.Select(new PdfDocumentArea(1, new PdfRectangle(90, 100, 240, 230)));

            // Highlight a selected text.