微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将 pdftron 注释添加到当前鼠标位置

如何解决如何将 pdftron 注释添加到当前鼠标位置

我正在使用 pdftron 编写 pdf 阅读软件。我知道 docViewer.on('mouseLeftDown',e => {} 可以获取事件,但 onClick 似乎无法获取鼠标事件。有什么好的解决办法吗?谢谢。

      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

解决方法

我认为您可以这样做的一种方法是侦听 iframe 文档上的 contextmenu 事件,然后从那里存储最后一个鼠标事件,然后您可以在按钮的 onClick 中使用该事件。

例如

let lastContextMenuEvent;

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

instance.contextMenuPopup.add({
  onClick: () => {
     // use lastContextMenuEvent here
  }
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。