Back to Devexpress

Annotations in WPF PDF Viewer

wpf-119630-controls-and-libraries-pdf-viewer-additional-content-annotations.md

latest7.0 KB
Original Source

Annotations in WPF PDF Viewer

  • May 27, 2025
  • 3 minutes to read

The PDF Viewer allows you to create, edit, or remove text annotations (sticky notes) and text markup annotations (text highlights). You can also add comments and reviews associated with annotations.

Create an Annotation

User Interface

Use commands on the Comment ribbon page to create text markup annotations and sticky notes.

Enable a selection tool in the Text group and select the text that should have an annotation. Click Sticky Note to place the sticky note in a document.

You can also add text markup annotations from the context menu:

Tip

Use the PdfViewerControl.CursorMode property to change the viewer’s cursor mode in code.

Code

The following API allows you to add annotations in code:

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 code below highlights the selected text and adds a sticky note:

View Example

csharp
using DevExpress.Pdf;
using DevExpress.Xpf.DocumentViewer;
using DevExpress.Xpf.PdfViewer;

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

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

Change Markup Tool Settings

User Interface

You can change the default settings for annotation tools. Click the drop-down arrow in the corresponding annotation tool and specify the color and opacity.

Code

To access the markup tool settings in code, use the PdfViewerControl.MarkupToolsSettings property.

The code sample below shows how to specify the default sticky note and text highlight settings:

xaml
<dxpdf:PdfViewerControl>
    <dxpdf:PdfViewerControl.MarkupToolsSettings>
        <dxpdf:PdfMarkupToolsSettings StickyNoteIconName="Help"
                                      StickyNoteColor="SkyBlue"
                                      TextHighlightColor="IndianRed"
                                      TextHighlightDefaultSubject="Spelling"/>
    </dxpdf:PdfViewerControl.MarkupToolsSettings>
</dxpdf:PdfViewerControl>

Edit Annotations

Use the Annotation Properties dialog to change the annotation properties. Right-click the annotation in the document or in the Comments navigation page and select Properties… to invoke this dialog.

Click Set as Default to use the new settings as the default settings for all annotations.

Add Replies and Reviews

The Comments navigation pane shows all document annotations. You can use it to add replies and set review statuses for the annotations.

Select an annotation on the pane, enter text in the invoked editor and click Reply to add the reply to the annotation.

To specify the review status, right-click an annotation, select Set Status , and set the status. Select None to remove the review status.

Remove Annotations

Right-click an annotation in document or in the Comments navigation pane and select Delete in the context menu to remove the annotation. You can also select an annotation and press the Delete key.

Annotation Events

The table below lists events that occur in response to various annotation actions:

EventDescription
AnnotationCreatingFires when the user starts to create an annotation or after the corresponding method call.
AnnotationCreatedRaises after the annotation is created.
AnnotationGotFocusOccurs when the annotation receives the input focus.
AnnotationLostFocusFires when the annotation loses the input focus.
AnnotationChangingOccurs when the user starts to change an annotation.
AnnotationChangedOccurs after the user changed the annotation using the Annotation Properties dialog.
AnnotationDeletingOccurs before the annotation is deleted.
AnnotationDeletedOccurs after the annotation is deleted.
ReplyCreatedOccurs after the annotation reply is created in the Comments Panel.
ReplyChangedOccurs after the annotation reply is changed in the Comments Panel.
ReplyDeletedOccurs after the annotation reply is deleted in the Comments Panel.