Annotation Toolbar

You can customize the annotation toolbars for the document viewers.

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.

Apryse Docs Image

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

Apryse Docs Image

Small devices in portrait mode

Apryse Docs Image

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:

C#

1var annotationToolbar = new pdftron.PDF.Controls.PTAnnotationToolbar(mToolManager);
2annotationToolbar.AnnotationToolbarDidCancel += (sender, e) =>
3{
4 annotationToolbar.Hidden = true;
5};
6View.AddSubview(annotationToolbar);
7
8// position annotation toolbar
9annotationToolbar.TranslatesAutoresizingMaskIntoConstraints = false;
10NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] {
11 annotationToolbar.LeadingAnchor.ConstraintEqualTo(this.View.LeadingAnchor),
12 annotationToolbar.WidthAnchor.ConstraintEqualTo(this.View.WidthAnchor),
13 annotationToolbar.TopAnchor.ConstraintEqualTo(this.View.LayoutMarginsGuide.TopAnchor)
14});
15
16// hide annotation toolbar by default
17annotationToolbar.Hidden = true;

To show:

C#

1// Show the annotation toolbar.
2annotationToolbar.Hidden = false;

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.

C#

1annotationToolbar.AnnotationToolbarDidCancel += (sender, e) =>
2{
3 annotationToolbar.Hidden = true;
4}

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:

C#

1mAnnotationToolbar.ToolShouldGoBackToPan = (annotationToolbar) =>
2{
3 return false;
4};

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

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales