For the complete documentation index, see llms.txt. This page is also available as Markdown.

Annotation Toolbar

You can customize the annotation toolbars for the document viewers.

Customize annotation toolbar for Xamarin.Android viewer

This tutorial only applies to Xamarin.Android. See Xamarin.iOS equivalent here .

AnnotationToolbarComponent is a class that contains the logic and views that make up the annotation toolbar. The annotation toolbar can be customized to contain a number of annotation creation tools button as well as any custom button. With the annotation toolbar, users are able to conveniently create annotations and switch between different tools.

The buttons on the annotation toolbar are contained in two groups: the scrollable region (left) and the sticky region (right). The scrollable region can contain any number of buttons and scrolling is used to access buttons that are off-screen. Buttons in the sticky region will always show on the screen and will not be scrollable.

To learn more about each icon, see the icon cheat sheet .

Create a custom annotation toolbar

The annotation toolbar allows users to easily switch tools when adding annotations to a document. To add an annotation toolbar to your app, first define some layout groups in your app that will contain the annotation toolbar:

Then in your activity, setup your AnnotationToolbarComponent with ToolManager and attach the required ViewModel classes:

Finally, you can customize the annotation toolbar by either using one of our default toolbars or creating a custom toolbar from scratch.

Show and hide annotation toolbar

Hide annotation toolbar items

If you have used ToolManager to hide certain tools, then the associated tool buttons will also be hidden in the annotation toolbar.

Hide tool buttons

If there are tools that you would like to remove from the annotation toolbar, you can disable them by calling ToolManager.disableToolMode(ToolMode[]). This will also hide the tool in the quick menu. For example:

For reference, a mapping of ToolMode to button icons is shown below:

Icon
ToolMode

RECT_CREATE

OVAL_CREATE

POLYLINE_CREATE

POLYGON_CREATE

CLOUD_CREATE

LINE_CREATE

ARROW_CREATE

RULER_CREATE

TEXT_CREATE

CALLOUT_CREATE

TEXT_ANNOT_CREATE

INK_CREATE

INK_ERASER

SIGNATURE

STAMPER

RUBBER_STAMPER

FREE_HIGHLIGHTER

TEXT_HIGHLIGHT

TEXT_UNDERLINE

TEXT_SQUIGGLY

TEXT_STRIKEOUT

ANNOT_EDIT_RECT_GROUP

Annotation toolbar listener

You can set an AnnotationButtonClickListener to be notified of annotation toolbar button click events.

Edit annotations continuously

For continuous annotation creation, AnnotationToolbarComponent will use value set by PdfViewCtrlSettingsManager.setContinuousAnnotationEdit(Context, boolean) (by default true). If continuous annotation editing is disabled, then the tool button will be de-selected in the annotation toolbar after creating an annotation.

Appearance styles

In order to customize the appearance of UI elements in your annotation toolbar, you can define a new style that extends PTAnnotationToolbarTheme inside your res\values\style.xml file and pass it as an attribute to your viewer's theme named pt_annotation_toolbar_style. For more information on customizing the style of UI components, please take a look at our viewer theme guide .

Customize annotation toolbar for Xamarin.iOS viewer

This tutorial only applies to Xamarin.iOS. See Xamarin.Android equivalent here .

The PTAnnotationToolbar class is a UIToolbar consisting of various annotation creation tools. With the annotation toolbar, users are able to conveniently create and switch between different tools.

The annotation toolbar control is part of the Tools library, so make sure you have added it to your project.

** Due to space limitations, only a limited number of tools will show up in portrait mode on smaller devices. See the customization section of this guide for more details on how to customize this. **

Scenario
Annotation Toolbar

Small devices in landscape mode + Tablet devices

Small devices in portrait mode

Show and hide the annotation toolbar

To create and set up an annotation toolbar, initialize an AnnotationToolbar instance and add it to your view hierarchy:

To show:

Customization

The PTAnnotationToolbar class provides an API for specifying which tools are displayed in the toolbar when there is insufficient space to show them all. This is controlled by the PrecedenceArray property.

Annotation toolbar delegate

The PTAnnotationToolbarDelegate protocol allows the adopting class (usually the containing view controller, as in this guide) to be notified of annotation toolbar events and control the behavior of the toolbar.

Edit annotations continuously

By default, the annotation toolbar returns to the pan tool after an annotation is created. If you prefer to stay in the same tool mode after an annotation is created, you should implement the toolShouldGoBackToPan method in your AnnotationToolbarDelegate adopting class:

The annotation toolbar's behavior could also be handled within user settings by checking and returning the appropriate settings value in the method above.

Last updated

Was this helpful?