# Get Page Number of current cursor location

**URL:** <https://pdfjs.community/t/get-page-number-of-current-cursor-location/3271>\
**Category:** Technical Support\
**Created:** [May 10, 2024, 12:39am UTC](https://pdfjs.community/t/get-page-number-of-current-cursor-location/3271 "2024-05-10T00:39:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dale](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@dale](https://pdfjs.community/u/dale)\
**Post date:** [May 10, 2024, 12:39am UTC](https://pdfjs.community/t/get-page-number-of-current-cursor-location/3271/1 "2024-05-10T00:39:36Z")

</div>

**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?

---

<div class="post-metadata">

**Author:** ![ejohnson](https://avatars.discourse-cdn.com/v4/letter/e/a3d4f5/32.png) [@ejohnson](https://pdfjs.community/u/ejohnson)\
**Post date:** [May 10, 2024, 2:25pm UTC](https://pdfjs.community/t/get-page-number-of-current-cursor-location/3271/3 "2024-05-10T14:25:24Z")

</div>

Thank you for posting your question to our forum. We will provide you with an update as soon as possible.

---

<div class="post-metadata">

**Author:** ![dale](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@dale](https://pdfjs.community/u/dale)\
**Post date:** [May 11, 2024, 9:57am UTC](https://pdfjs.community/t/get-page-number-of-current-cursor-location/3271/4 "2024-05-11T09:57:01Z")

</div>

```javascript
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
