1

I am writing a pdf reading software using pdftron. I know that docViewer.on('mouseLeftDown', e => {} can get an event, but onClick can’t seem to get a mouse event. Is there any good solution? Thank you.

      WebViewer(
        {
          path,
          initialDoc: "",
        },
        viewer.value
      ).then(function (instance) {
        const { Annotations, annotManager, docViewer } = instance;
        instance.contextMenuPopup.add({
          type: "actionButton",
          label: "MD",
          onClick: () => {
            const freeText = new Annotations.FreeTextAnnotation();
            freeText.PageNumber = docViewer.getCurrentPage();
            freeText.X=?;// I don't know how to set the freeText.X at the location of the mouse
            freeText.Y=?;
            freeText.Width = 150;
            freeText.Height = 50;

create-annotation-free-text

converting-between-mouse-locations-and-window-coordinates

Cpcp Cp
  • 73
  • 3

1 Answers1

1

I think one way you could do it is to listen to the contextmenu event on the iframe document and then store the last mouse event from there that you can then use in the onClick of your button.

For example

let lastContextMenuEvent;

instance.iframeWindow.document.addEventListener('contextmenu', (e) => {
  lastContextMenuEvent = e;
});

instance.contextMenuPopup.add({
  onClick: () => {
     // use lastContextMenuEvent here
  }
});
mparizeau
  • 663
  • 5
  • 12