如何将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;

创建注释自由文本

在鼠标位置和窗口坐标之间转换

我认为一种方法是监听iframe文档上的contextmenu事件,然后存储最后一个鼠标事件,然后可以在按钮的onClick中使用。

例如

let lastContextMenuEvent;
instance.iframeWindow.document.addEventListener('contextmenu', (e) => {
lastContextMenuEvent = e;
});
instance.contextMenuPopup.add({
onClick: () => {
// use lastContextMenuEvent here
}
});

最新更新