I display pdf documents in an iframe on my website (all documents are stored in the same domain).
I would like users to be able to click in the document to add comments at a specific location. To do this, I am looking for a way to get the coordinate inside of an iframe (when we click).
It does not seem possible... However, there are paid solutions that offer this kind of functionality. Example : https://pdfjs.express/demo So, what process is used?
Thanks for you help.
You can get the coordinate of a click using the onmousedown event. The event gives you a MouseEvent object that contains the x and y coordinate of the click relative to the view port.
To get the coordinate relative to your iframe you have to subtract offsetLeft and offsetTop
var iframe = document.getElementById("iframe")
onmousedown = function(e) {
document.getElementById("position").textContent = "Mouse position: " + (e.clientX - iframe.offsetLeft) + " | " + (e.clientY - iframe.offsetTop)
}
Edit
You could use PDF.js and a canvas instead of a simple iframe to better controll the PDF-viewer.