Customizing an existing annotation tool in our viewer toolbar

It’s possible to customize the following properties of built-in items:

  • title
  • className
  • disabled
  • onPress

In the example below, we add a custom onPress handler to the first item of the ink annotation toolbar:

PSPDFKit.load({
// ...otherOptions
annotationToolbarItems: (
annotation,
{ defaultAnnotationToolbarItems }
) => {
if (annotation instanceof PSPDFKit.Annotations.InkAnnotation) {
defaultAnnotationToolbarItems[0].onPress = () =>
alert("Custom onPress handler!");
return defaultAnnotationToolbarItems;
}
return defaultAnnotationToolbarItems;
}
});

See the API reference to learn more about each individual property.

When you set onPress, it’s added to the parent of the built-in annotation toolbar item.