dale
May 10, 2024, 12:39am
1
Which product are you using?
PDF.js Express Viewer
PDF.js Express Version
8.7.4
Detailed description of issue
Get Page Number of mouse cursor
Expected behaviour
I am using an onDrop method to create an annotation. If the page I am dropping on isn’t the majoriry of view then getCurrentPage() will drop it on the majority view page.
annotation.PageNumber = webViewer.Core.documentViewer.getCurrentPage();
How can I get the pagenumber that the cursor is over?
Thank you for posting your question to our forum. We will provide you with an update as soon as possible.
dale
May 11, 2024, 9:57am
4
function getMouseLocation(e: DragEvent) {
if (!webViewer) return;
const documentViewer = webViewer.Core.documentViewer;
const scrollElement = documentViewer.getScrollViewElement();
const scrollLeft = scrollElement.scrollLeft || 0;
const scrollTop = scrollElement.scrollTop || 0;
const x = {
x: e.pageX + scrollLeft,
y: e.pageY + scrollTop,
};
return x;
}
const windowCoordinates = getMouseLocation(e);
const page = displayMode.getSelectedPages(windowCoordinates, windowCoordinates);
const clickedPage = page.first !== null ? page.first : documentViewer.getCurrentPage();
const pageCoordinates = displayMode.windowToPage(windowCoordinates, clickedPage);
const pageNumber = pageCoordinates.pageNumber;
This seems to work