javascript - 如何将 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
}
});
推荐阅读
- c# - 从 Log4Net LogManager 获取 Appender
- python - 使用 python 日志记录模块的操作系统相关行为
- c# - Revit API 无法在通用模型自适应族文档中创建新扫描
- iis - 我可以将 IIS 配置为在通过 IP 访问页面时显示自定义 404 吗?
- sql-server - 如何跟踪相应存储过程中的哪个查询正在执行
- javascript - 无法正确格式化数字
- javascript - 通过 javascript 触发数据工厂管道
- magento - Magento 致命错误:接口“Varien_Data_Form_Element_Renderer_Interface”
- kotlin - 为什么生成自动后端字段时必须初始化属性
- xamarin - 帧波纹轻拍效果