Posted 27 April 2023, 3:23 am EST
Hi,
Please refer to the following code snippet to add the Annotation on the specified path on Mouseclick:
document.addEventListener("click", (e) => {
const target = (e["path"] || (e["composedPath"] && e["composedPath"]()) || [])[0] || e.target, page = target.closest(".page");
if(target.closest(".gc-annotation"))
return;
if(page) {
const pageIndex = page.getAttribute("data-index") * 1, pageLoc = viewer.getPageLocation(pageIndex), scale = viewer.getViewPort(pageIndex).scale;
const x = (e.clientX - pageLoc.x) / scale, y = (e.clientY - pageLoc.y) / scale;
const rect = viewer.changeBoundsOrigin(pageIndex, [x, y, x + 20, y + 20], "TopLeft", "BottomLeft");
viewer.addAnnotation(pageIndex, { annotationType: 1 , contents: "Text annotation content", rect });
}
});
This method uses the getPageLocation() to get the position of the page view relative to the browser window.
Regards,
Manish Gupta