Back to Devexpress

PdfViewerControl.AnnotationCreating Event

wpf-devexpress-dot-xpf-dot-pdfviewer-dot-pdfviewercontrol-01b54036.md

latest8.7 KB
Original Source

PdfViewerControl.AnnotationCreating Event

Fires before the annotation is created.

Namespace : DevExpress.Xpf.PdfViewer

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

NuGet Package : DevExpress.Wpf.PdfViewer

Declaration

csharp
public event PdfAnnotationCreatingEventHandler AnnotationCreating
vb
Public Event AnnotationCreating As PdfAnnotationCreatingEventHandler

Event Data

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

PropertyDescription
BuilderGets the object used to build an annotation.
CancelGets or sets whether the event should be canceled.
HandledGets 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.
OriginalSourceGets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEventGets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
SourceGets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.

The event data class exposes the following methods:

MethodDescription
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:

MethodDescription
PdfViewerControl.HighlightSelectedTextHighlights the selected text.
PdfViewerControl.StrikethroughSelectedTextStrikes through the selected text.
PdfViewerControl.UnderlineSelectedTextUnderlines the selected text.
PdfViewerControl.AddStickyNoteAdds 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

csharp
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");
        }
    }
}
vb
Imports DevExpress.Pdf
Imports DevExpress.Xpf.DocumentViewer
Imports DevExpress.Xpf.PdfViewer
Imports System.Windows

Namespace MarkupAnnotations

Partial Public Class MainWindow
    Inherits DevExpress.Xpf.Core.ThemedWindow

    Public Sub New()
        InitializeComponent()

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

        AddHandler viewer.AnnotationCreating, AddressOf Viewer_TextMarkupAnnotationCreating

    End Sub

    Private Sub Viewer_TextMarkupAnnotationCreating
    (ByVal d As DependencyObject, ByVal e As PdfAnnotationCreatingEventArgs)
        If e.Builder.AnnotationType = PdfAnnotationType.Text
         OrElse e.Builder.AnnotationType = PdfAnnotationType.TextMarkup Then
            Dim annotationBuilder As IPdfViewerMarkupAnnotationBuilder =
             e.Builder.AsMarkupAnnotationBuilder()

            annotationBuilder.Author = "John Smith"
            annotationBuilder.Contents = "Note"
            annotationBuilder.Color = New PdfRGBColor(0.23, 0.48, 0.34)
        End If
    End Sub

    Private Sub viewer_DocumentLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
        ' Select the text to highlight:
        viewer.FindText
        (New TextSearchParameter With {.Text = "PDF Viewer"})

        ' Highlight selected text:
        viewer.HighlightSelectedText()

        'Add a sticky note:
        viewer.AddStickyNote
        (New PdfDocumentPosition(1, New PdfPoint(29, 568)), "Comment")
    End Sub
End Class
End Namespace

See Also

PdfViewerControl Class

PdfViewerControl Members

DevExpress.Xpf.PdfViewer Namespace