Create a New Annotation Tool in Our Viewer Toolbar
The main differentiator between built-in toolbar items and user-defined ones is the Id
, which is used to explicitly identify the latter. You can add one of the built-in types or a custom toolbar item of CustomAnnotationToolbarItem
type to the annotation toolbar. All these types are subclasses of AnnotationToolbarItems
:
using static PSPDFKit.Sdk.Models.Toolbar.AnnotationToolbarItems; ... var toolbarItem = new CustomAnnotationToolbarItem("customItemId") { Icon = "newIcon.svg", Tooltip = "My button" }; toolbarItem.Clicked += (s, e) => Debug.WriteLine("My toolbar item clicked");
When the Icon
for a button is missing, the Tooltip
will instead be displayed as Button.Text
. This is useful if you want to create text-only buttons.
A Clicked
event is invoked when a button is either clicked or tapped (on touch devices).
Once the custom button is ready, it’s possible to insert it into the current list of any annotation type:
PSPDFKitController.AnnotationToolbar.ToolbarItems[AnnotationType.Ink].Add(toolbarItem);
Toolbar Layout and the Spacer Item
The items list is rendered as a flat list of sibling elements that are separated by a special toolbar item called SpacerAnnotationToolbarItem
. This solution makes the toolbar layout flexible and easy to customize.
SpacerAnnotationToolbarItem
is an empty element, and it pushes items from both sides together, making them more compact. You can insert as many spacer items as you want.