windowsforms-119479-controls-and-libraries-pdf-viewer-additional-content-annotations.md
The PDF Viewer allows you to add interactive elements ( annotations ) such as notes, highlights, or text boxes directly to a PDF document. You can create and delete annotations, edit their content or flatten them, add related comments and reviews. All these capabilities allow you to add context or feedback directly to PDF files and thus simplify collaboration during document reviews.
Note
The PDF Viewer ignores the No Rotate and No Zoom annotation flags.
Highlight
Highlight text and leave comments about it.
Strikethrough
Strike out text and leave comments about it.
Underline
Underline text and leave comments about it.
Sticky Notes
Add a comment annotation to a specific location in a PDF document.
Free Text Annotations
Insert a text box at a specific location in a PDF document.
Callouts
Insert a combination of a text box and a pointer line to a specific location in a PDF document.
Use commands on the Comment Ribbon page to create text markup annotations, sticky notes, free text, and callouts.
Enable one of the selection tools in the Text group and select the text that should have an annotation:
You can also add text markup annotations for the selected text from the context menu:
Click Sticky Note , Free Text , or Callout in the Ribbon and select a location in a PDF document to place the element:
Tip
Use the PdfViewer.CursorMode property to change the viewer’s cursor mode in code.
The following API allows you to add annotations in code:
| Method | Description |
|---|---|
| PdfViewer.HighlightSelectedText | Highlights the selected text. |
| PdfViewer.StrikethroughSelectedText | Strikes through the selected text. |
| PdfViewer.UnderlineSelectedText | Underlines the selected text. |
| PdfViewer.AddStickyNote | Adds a sticky note at the specified position. |
The code below highlights the selected text and adds a sticky note.
using System.Drawing;
using System.Windows.Forms;
// Load a document
pdfViewer.LoadDocument("..\\..\\Demo.pdf");
// Select a text to highlight
pdfViewer.FindText("PDF Viewer");
// Highlight selected text
pdfViewer.HighlightSelectedText();
// Add a sticky note
pdfViewer.AddStickyNote(new PdfDocumentPosition(1, new PdfPoint(29, 568)),
"Comment", Color.Crimson);
Imports System.Drawing
Imports System.Windows.Forms
' Load a document
pdfViewer.LoadDocument("..\..\Demo.pdf")
' Select a text to highlight
pdfViewer.FindText("PDF Viewer")
' Highlight selected text
pdfViewer.HighlightSelectedText()
pdfViewer.AddStickyNote(New PdfDocumentPosition(1, New PdfPoint(29, 568)), "Comment", Color.Crimson)
You can also use PDF Facade API to access and manage annotations. This API implements additional functionality, but is only available as part of DevExpress Office File API * or Universal subscription. Navigate to the following section for additional information and a code sample: Use PDF Facade API to Manage Annotations.
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.
To access the markup tool settings in code, use the PdfViewer.MarkupToolsSettings property.
The following code sample specifies the default sticky note and text highlight settings:
PdfMarkupToolsSettings markupToolsSettings = pdfViewer.MarkupToolsSettings;
markupToolsSettings.StickyNoteIconName = PdfTextAnnotationIconName.Help;
markupToolsSettings.StickyNoteColor = Color.SkyBlue;
markupToolsSettings.TextHighlightColor = Color.IndianRed;
markupToolsSettings.TextHighlightDefaultSubject = "Spelling";
Dim markupToolsSettings As PdfMarkupToolsSettings = pdfViewer.MarkupToolsSettings
markupToolsSettings.StickyNoteIconName = PdfTextAnnotationIconName.Help
markupToolsSettings.StickyNoteColor = Color.SkyBlue
markupToolsSettings.TextHighlightColor = Color.IndianRed
markupToolsSettings.TextHighlightDefaultSubject = "Spelling"
Right-click the annotation in the document (or in the Comments navigation page) and select Properties :
Use the invoked Annotation Properties dialog to edit the annotation (text and border colors, opacity, text, and so on). Available properties depend on the annotation type:
Click Set as Default to change default settings for all new annotations of this type.
Users can move Sticky Notes, Free Text, and Callouts:
Users can move pointer lines associated with Callout annotations:
Users can resize Free Text and Callout annotations:
Tip
When the Comments panel is opened, double-click a sticky note to edit its associated comment.
The Comments navigation pane (Alt + C) shows all document annotations. You can use it to add replies and set review statuses for 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 choose an option. Select None to retract your response:
Right-click an annotation in the Comments navigation pane and select Delete in the context menu to remove the annotation:
Users can also click an annotation in a document and press Delete or right-click and choose Delete from the context menu:
The table below lists the PdfViewer events that occur in response to various annotation actions:
AnnotationCreatingFires before the annotation is created.AnnotationCreatedOccurs after an annotation is created.AnnotationGotFocusOccurs when an annotation receives input focus.AnnotationLostFocusOccurs when an annotation loses input focus.AnnotationChangingFires before the annotation is changed.AnnotationChangedFires after an annotation has been changed.AnnotationDeletingFires before an annotation is deleted from a page.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.
Important
Functionality in this section is available as part of the DevExpress Office File API or Universal Subscription. Refer to the DevExpress Subscription page for pricing information.
The PDF Facade API contains additional annotation types you can manage in code: Link, Rubber Stamp, Caret, File Attachment, Ink, and others. You can use the PdfDocumentFacade class to organize these annotations: create, delete, edit their content, flatten, add related comments and reviews.
The PdfViewerExtensions.GetDocumentFacade method retrieves the PdfDocumentFacade class object that allows you to change the PDF document without access to its inner structure.
The PdfPageFacade.Annotations property retrieves all page annotation properties. Use the PdfDocumentFacade.Pages property to access the PdfPageFacade class.
The following code sample creates a file attachment and a rubber stamp annotation:
pdfViewer.LoadDocument("Document.pdf");
// Access the first page properties
PdfDocumentFacade documentFacade = pdfViewer.GetDocumentFacade();
PdfPageFacade pageFacade = documentFacade.Pages[0];
// Define a rubber stamp rectangle
PdfRectangle rubberStampRectangle = new PdfRectangle(491, 727, 591, 773);
// Create a "Draft" rubber stamp annotation
PdfRubberStampAnnotationFacade rubberStamp =
pageFacade.AddRubberStampAnnotation(rubberStampRectangle,
PdfRubberStampAnnotationIconName.Draft);
rubberStamp.Author = "Jesse Faden";
rubberStamp.Contents = "Made in PDF Document API";
// Define a file attachment area
PdfPoint attachmentPoint = new PdfPoint(29, 568);
// Specify attachment data
PdfFileAttachment attachment = new PdfFileAttachment()
{
CreationDate = DateTime.Now,
Description = "This is my attached file",
FileName = "MyAttach.txt",
Data = File.ReadAllBytes("..\\..\\Attachment.txt")
};
// Create a file attachment annotation
PdfFileAttachmentAnnotationFacade pdfFileAttachment =
pageFacade.AddFileAttachmentAnnotation(attachmentPoint, attachment,
PdfFileAttachmentAnnotationIconName.PaperClip);
pdfFileAttachment.Author = "Nancy Skywalker";
pdfFileAttachment.Contents = "Additional Content";
pdfViewer.LoadDocument("Document.pdf")
' Access the first page properties
Dim documentFacade As PdfDocumentFacade = pdfViewer.GetDocumentFacade()
Dim pageFacade As PdfPageFacade = documentFacade.Pages(0)
' Define a rubber stamp rectangle
Dim rubberStampRectangle As New PdfRectangle(491, 727, 591, 773)
' Create a "Draft" rubber stamp annotation
Dim rubberStamp As PdfRubberStampAnnotationFacade =
pageFacade.AddRubberStampAnnotation(rubberStampRectangle, PdfRubberStampAnnotationIconName.Draft)
rubberStamp.Author = "Jesse Faden"
rubberStamp.Contents = "Made in PDF Document API"
' Define a file attachment area
Dim attachmentPoint As New PdfPoint(29, 568)
' Specify attachment data
Dim attachment As New PdfFileAttachment() With {.CreationDate = Date.Now, .Description = "This is my attached file", .FileName = "MyAttach.txt", .Data = File.ReadAllBytes("..\..\Attachment.txt")}
' Create a file attachment annotation
Dim pdfFileAttachment As PdfFileAttachmentAnnotationFacade =
pageFacade.AddFileAttachmentAnnotation(attachmentPoint, attachment, PdfFileAttachmentAnnotationIconName.PaperClip)
pdfFileAttachment.Author = "Nancy Skywalker"
pdfFileAttachment.Contents = "Additional Content"
Refer to the following article for more information on how to use PDF Facade API to manage annotations: How to: Use PDF Facade API to Manage Annotations.
See Also