Get X and Y coordinates of currently rendered page

Product: Apryse PDFTron SDK
Product Version: 10.2.3

I want to find the X and Y coordinates of the portion of the page that is currently rendered in the webviewer viewport.

I have tried using " getExactViewportRegionRect()" and " getViewportRegionRect()" after enabling viewport rendering by calling the " enableViewportRenderMode()" function on the documentViewer instance.

Any help with this issue will be appreciated.

Thanks,
Subhrajyoti Behera

Thank you for contacting Apryse support.

I’m reviewing your request and will get back to you shortly.

Hi there,

The APIs you mentioned is correct, please try using it after the document has loaded:

documentViewer.enableViewportRenderMode();
const viewPortRegion = documentViewer.getExactViewportRegionRect(documentViewer.getCurrentPage())
console.log(viewPortRegion);

This is the result returned:

Best regards,
Kevin Kim

Hello Kevin, the above code did not work for me, I am still getting null from the getExactViewportRegionRect() function.

I have tried it with two different scenarios

  1. documentViewer.addEventListener(“documentLoaded”, () => {
    documentViewer.enableViewportRenderMode();
    const viewPortRegion = documentViewer.getExactViewportRegionRect(
    documentViewer.getCurrentPage()
    );
    console.log("VIEWPORT REGION IS ", viewPortRegion);
    });

  2. documentViewer.addEventListener(“mouseLeftDown”, (eventObj) => {
    documentViewer.enableViewportRenderMode();
    const viewPortRegion = documentViewer.getViewportRegionRect(
    documentViewer.getCurrentPage()
    );
    console.log("VIEWPORT REGION IS ", viewPortRegion);
    });

I got null in both the cases.

Hi there,

Thank you for your response,

Based on this forum post Get current page view/viewport as an image
It looks like viewport is dependent on the zoom. If the page is fully visible on the viewer, then viewport mode is not enabled/ becomes disabled

You can test this by zooming in and using the isInViewportRenderMode API

Best regards,
Kevin Kim