Removing an Annotation Tool from Our Viewer Toolbar

PSPDFKit for Web comes with a customizable annotation toolbar that, by default, includes a number of predefined items. You can remove any toolbar item you want using our API.

Launch Demo

In the example below, we’re removing the blend-mode item from the ink annotation toolbar when loading the PDF:

PSPDFKit.load({
  // ...otherOptions
  annotationToolbarItems: (
    annotation,
    { defaultAnnotationToolbarItems }
  ) => {
    if (annotation instanceof PSPDFKit.Annotations.InkAnnotation) {
      // Remove the default annotation toolbar item.
      return defaultAnnotationToolbarItems.filter(
        (item) => item.type !== "blend-mode"
      );
    }

    return defaultAnnotationToolbarItems;
  }
});

We can also change the annotation toolbar once the PDF has loaded using instance.setAnnotationToolbarItems:

instance.setAnnotationToolbarItems(
  (annotation, { defaultAnnotationToolbarItems }) => {
    if (annotation instanceof PSPDFKit.Annotations.InkAnnotation) {
      // Remove the default annotation toolbar item.
      return defaultAnnotationToolbarItems.filter(
        (item) => item.type !== "blend-mode"
      );
    }

    return defaultAnnotationToolbarItems;
  }
);