Skip to main content
All docs
V23.2

PdfViewerControl.AnnotationCreating Event

Fires before the annotation is created.

Namespace: DevExpress.Xpf.PdfViewer

Assembly: DevExpress.Xpf.PdfViewer.v23.2.dll

NuGet Package: DevExpress.Wpf.PdfViewer

Declaration

public event PdfAnnotationCreatingEventHandler AnnotationCreating

Event Data

The AnnotationCreating event's data class is PdfAnnotationCreatingEventArgs. The following properties provide information specific to this event:

Property Description
Builder Gets the object used to build an annotation.
Cancel Gets or sets whether the event should be canceled.
Handled Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.
OriginalSource Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEvent Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
Source Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.

The event data class exposes the following methods:

Method Description
InvokeEventHandler(Delegate, Object) When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.
OnSetSource(Object) When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.

Remarks

The AnnotationCreating event fires when the user creates an annotation from the User Interface or after one of the following methods are called:

Method Description
PdfViewerControl.HighlightSelectedText Highlights the selected text.
PdfViewerControl.StrikethroughSelectedText Strikes through the selected text.
PdfViewerControl.UnderlineSelectedText Underlines the selected text.
PdfViewerControl.AddStickyNote Adds a sticky note at the specified position.

The PdfAnnotationCreatingEventArgs.Builder property retrieves the annotation parameters. Use the DevExpress.Pdf.PdfViewerAnnotationBuilderExtensions class methods to obtain a specific type of annotation.

The following code shows how to handle the PdfViewerControl.AnnotationCreating event:

View Example

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

namespace MarkupAnnotations
{

    public partial class MainWindow : DevExpress.Xpf.Core.ThemedWindow
    {
        public MainWindow()
        {
            InitializeComponent();

            // Load a document.
            viewer.OpenDocument("..\\..\\Demo.pdf");

            viewer.AnnotationCreating += Viewer_TextMarkupAnnotationCreating;
        }

        private void Viewer_TextMarkupAnnotationCreating
        (DependencyObject d, PdfAnnotationCreatingEventArgs e)
        {
            if (e.Builder.AnnotationType == PdfAnnotationType.Text 
            || e.Builder.AnnotationType == PdfAnnotationType.TextMarkup)
            {
                IPdfViewerMarkupAnnotationBuilder annotationBuilder =
                 e.Builder.AsMarkupAnnotationBuilder();

                annotationBuilder.Author = "John Smith";
                annotationBuilder.Contents = "Note";
                annotationBuilder.Color = new PdfRGBColor(0.23, 0.48, 0.34);
            }
        }

        private void viewer_DocumentLoaded(object sender, RoutedEventArgs e)
        {
            // Select the text to highlight:
            viewer.FindText
            (new TextSearchParameter { Text = "PDF Viewer" });

            // Highlight selected text:
            viewer.HighlightSelectedText();

            //Add a sticky note:
            viewer.AddStickyNote
            (new PdfDocumentPosition(1, new PdfPoint(29, 568)), "Comment");
        }
    }
}
See Also