From 1678782680034c9d143915c3afd0a0ba593f9f57 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Sun, 24 Aug 2025 21:02:02 +0200 Subject: [PATCH] Add a method goToXY in PDFLinkService in order to scroll the document at a given location This function is required for the commenting feature: the user will be able to click on a comment in the sidebar and the document will be scrolled accordingly. --- web/interfaces.js | 8 ++++++++ web/pdf_link_service.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/web/interfaces.js b/web/interfaces.js index 620d571de..7c926af9c 100644 --- a/web/interfaces.js +++ b/web/interfaces.js @@ -73,6 +73,14 @@ class IPDFLinkService { */ goToPage(val) {} + /** + * Scrolls to a specific location in the PDF document. + * @param {number} pageNumber - The page number to scroll to. + * @param {number} x - The x-coordinate to scroll to in page coordinates. + * @param {number} y - The y-coordinate to scroll to in page coordinates. + */ + goToXY(pageNumber, x, y) {} + /** * @param {HTMLAnchorElement} link * @param {string} url diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index a2cb46245..9f46a0475 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -239,6 +239,20 @@ class PDFLinkService { this.pdfViewer.scrollPageIntoView({ pageNumber }); } + /** + * Scrolls to a specific location in the PDF document. + * @param {number} pageNumber - The page number to scroll to. + * @param {number} x - The x-coordinate to scroll to in page coordinates. + * @param {number} y - The y-coordinate to scroll to in page coordinates. + */ + goToXY(pageNumber, x, y) { + this.pdfViewer.scrollPageIntoView({ + pageNumber, + destArray: [null, { name: "XYZ" }, x, y], + ignoreDestinationZoom: true, + }); + } + /** * Adds various attributes (href, title, target, rel) to hyperlinks. * @param {HTMLAnchorElement} link