Text Markup Annotations
- 4 minutes to read
When reviewing a document, you often need to draw attention to some important text the author can change later.
The PDF Viewer allows you to highlight, strikethrough, or underline text. You can also change the markup annotation properties (for example, add a comment to an annotation) or delete an annotation from a document.
The document includes the following sections:
Create Text Markup Annotation
To highlight, strikethrough or underline text, use:
The corresponding text markup tool located in the viewer's Comment toolbar
The text markup tools are available after opening a document in the PDF Viewer.
To add a markup to text:
- Click the corresponding tool button (for example, Highlight);
- Select the text.
The image below shows the text highlighted in the default color.
The viewer's context menu
To add a markup to text:
- Select the text;
Right-click the text and choose Highlight text, Strikethrough text or Underline text item in the invoked context menu.
To highlight, strikethrough or underline selected text in code, call one of the PdfViewerControl.HighlightSelectedText, PdfViewerControl.StrikethroughSelectedText or PdfViewerControl.UnderlineSelectedText overload methods.
Change default markup tool settings
You can customize the default markup tool settings that are applied to newly created markups.
To access the markup tool settings, use the PdfViewerControl.MarkupToolsSettings property.
<dxpdf:PdfViewerControl> <dxpdf:PdfViewerControl.MarkupToolsSettings> <dxpdf:PdfMarkupToolsSettings Author="Bill Smith"/> </dxpdf:PdfViewerControl.MarkupToolsSettings> </dxpdf:PdfViewerControl>
You can change, for example, the default color used to underline a text using the PdfMarkupToolsSettings.TextUnderlineColor property.
To change the default markup color at runtime, click the drop-down arrow in the corresponding text markup tool and select the required color.
The default markup settings can also be modified using the Annotation Properties dialog. See the Editing Text Markup Annotation section to learn how to invoke this dialog.
When the markup annotation is being created in a document, it raises the PdfViewerControl.AnnotationCreating event. In this event, you can specify the markup annotation properties and prohibit creating annotation.
Refer to the How to: Create a Text Markup Annotation and Specify its Properties example to learn more.
The PdfViewerControl class also provides the PdfViewerControl.AnnotationCreated event. This event is raised after the markup annotation is created. In this event, you can obtain the name of a created annotation.
Edit Text Markup Annotation
You can change the markup annotation properties using the Annotation Properties dialog.
For example, to add a comment to a markup annotation:
Right-click the annotation and choose the Properties... item in the context menu;
This invokes the Annotation Properties dialog.
- Type a text in the dialog's Comment text box.
- To save changes, click OK.
The Annotation Properties dialog also allows you to change default settings for annotation color, opacity, subject, and author. The default settings are applied to newly created markups. To set new settings as the default, click Set As Default.
If you want to cancel changes, click Cancel.
The PDF Viewer provides the PdfViewerControl.AnnotationChanged event. This event is raised after an end-user closes the Annotation Properties dialog if a text markup annotation has been changed. In this event, you can access the markup annotation settings (for example, the author of a text markup annotation using the Author property).
The comment is shown in the markup annotation's pop-up window.
The PDF Viewer also provides the PdfViewerControl.ShowAnnotationPropertiesCommand command to invoke this annotation properties dialog in code.
Remove Text Markup Annotation
To remove an annotation:
- Right-click the annotation;
Choose the Delete item in the invoked context menu.
- Select the annotation and press the Delete key.
You can also use the PdfViewerControl.DeleteAnnotationCommand command to delete the selected annotation programmatically.
When the markup annotation is being deleted, it raises the PdfViewerControl.AnnotationDeleting event. In this event, you can obtain the annotation name, annotation bounds on a page and the page number. In addition, you can prohibit deleting the annotation from a page.