Capture the current page number being viewed

31 Oct 20231 minute to read

The PDF Viewer server library allows you to capture the page number that is currently being viewed in the load PDF document. Use the currentPageNumber property to get the page number which is currently in view.

The following steps are used to capture the current page number.

Step 1: Follow the steps provided in the link to create a simple PDF Viewer sample.

Step 2: Use the following code snippet to Capture the current page number being viewed.

<button onclick="currentPage()">currentpage</button>

<div style="width:100%;height:600px">
    <ejs-pdfviewer 
        id="pdfviewer"
        documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf">
    </ejs-pdfviewer>
</div>

<script>
    function currentPage() {
        var viewer = document.getElementById('pdfviewer').ej2_instances[0];
        var pageNumber = viewer.currentPageNumber;
        alert("current page number is" + pageNumber);
    }
</script>
<button onclick="currentPage()">currentpage</button>

<div style="width:100%;height:600px">
    <ejs-pdfviewer 
        id="pdfviewer"
        documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
        serviceUrl='/Index'>
    </ejs-pdfviewer>
</div>

<script>
    function currentPage() {
        var viewer = document.getElementById('pdfviewer').ej2_instances[0];
        var pageNumber = viewer.currentPageNumber;
        alert("current page number is" + pageNumber);
    }
</script>

View sample in GitHub