openElements() not opening elements

Hi,

The reason why they don’t display in the viewer is that the toolStylePopup doesn’t know where it should locate itself.

You can listen to the toolModeUpdated event, check the tool names, and then open the component. The code below opens the style popup component when the current tool mode is rectangle tool.

instance.docViewer.on('toolModeUpdated', (currTool) => {
  if (currTool.name === 'AnnotationCreateRectangle') {
    setTimeout(() => {
      instance.openElements(['toolStylePopup']);
    }, 0);
  }
})

To gain max flexibility, I would suggest you to modify the UI source code, build it, and then integrate the custom UI into your app. If you are going this way then this guide can be helpful https://pdfjs.express/documentation/ui-customization/advanced-customization.

1 Like