Get Page Number of current cursor location

Which product are you using?
PDF.js Express Viewer

PDF.js Express Version

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.

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