Removing an Inline Text Selection Tool from the Viewer Toolbar

PSPDFKit for Web comes with a customizable inline text selection toolbar that, by default, includes some predefined items. You can remove the toolbar items using the API.

The example below removes every item except for highlighting from the inline text selection toolbar when loading a PDF on mobile:

PSPDFKit.load({
  // ...otherOptions
  inlineTextSelectionToolbarItems: (
    { defaultItems, hasDesktopLayout },
    selection
  ) => {
    console.log(selection);
    if (hasDesktopLayout) {
      const highlightItem = defaultItems.shift();
      return highlightItem;
    }
    return defaultItems;
  }
});

The example below changes the toolbar after the PDF has loaded using instance.setInlineTextSelectionToolbarItems:

instance.setInlineTextSelectionToolbarItems(
  ({ defaultItems, hasDesktopLayout }, selection) => {
    console.log(selection);
    if (hasDesktopLayout) {
      const highlightItem = defaultItems.shift();
      return highlightItem;
    }
    return defaultItems;
  }
);