Some test text!

Search
Hamburger Icon

Xamarin / Guides

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.

Annotation toolbar

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.
ScenarioAnnotation Toolbar
Small devices in landscape mode + Tablet devicesMobile device in landscape mode + Tablet device
Small devices in portrait modeMobile device 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:

var annotationToolbar = new pdftron.PDF.Controls.PTAnnotationToolbar(mToolManager);
annotationToolbar.AnnotationToolbarDidCancel += (sender, e) =>
{
    annotationToolbar.Hidden = true;
};
View.AddSubview(annotationToolbar);

// position annotation toolbar
annotationToolbar.TranslatesAutoresizingMaskIntoConstraints = false;
NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] {
    annotationToolbar.LeadingAnchor.ConstraintEqualTo(this.View.LeadingAnchor),
    annotationToolbar.WidthAnchor.ConstraintEqualTo(this.View.WidthAnchor),
    annotationToolbar.TopAnchor.ConstraintEqualTo(this.View.LayoutMarginsGuide.TopAnchor)
});

// hide annotation toolbar by default
annotationToolbar.Hidden = true;

To show:
// Show the annotation toolbar.
annotationToolbar.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.

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

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:

mAnnotationToolbar.ToolShouldGoBackToPan = (annotationToolbar) =>
{
    return false;
};

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

Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales