Get page info in the ASP.NET MVC PDF Viewer

28 Oct 20253 minutes to read

Use the getPageInfo() method to retrieve information for a specified page, including height, width, and rotation.

The following steps show how to use getPageInfo.

Step 1: Follow the steps in the Syncfusion ASP.NET MVC PDF Viewer getting started guide to create a sample.

Step 2: Use the following code to get the height, width, and rotation for a specified page.

@using Syncfusion.EJ2
@{
    ViewBag.Title = "Home Page";
}

<div>
    <div style="height:500px;width:100%;">
        <!-- Button to trigger Page Info retrieval -->
        <button id="getPageInfo">GetPageInfo</button>
        <!-- Render PDF Viewer -->
        @Html.EJS().PdfViewer("pdfviewer").DocumentPath("https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf").Render()
    </div>
</div>

<!-- Ensure necessary Syncfusion scripts and styles are included -->
<script src="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2.min.js"></script>
<script type="text/javascript">
    window.onload = function () {
        var viewer = document.getElementById('pdfviewer').ej2_instances[0];
        // Add event listener for retrieving page information
        document.getElementById('getPageInfo').addEventListener('click', function () {
            retrievePageInfo();
        });
        function retrievePageInfo() {
            if (viewer) {
                // Set the page index for which info is required
                const pageIndex = 0;
                // To Retrieve and log the page information
                console.log(viewer.getPageInfo(pageIndex));
                // To Log the specific page information details to the console
                var pageInfo = viewer.getPageInfo(pageIndex);
                if (pageInfo) {
                    console.log(`Page Info for Page Index ${pageIndex}:`);
                    console.log(`Height: ${pageInfo.height}`);
                    console.log(`Width: ${pageInfo.width}`);
                    console.log(`Rotation: ${pageInfo.rotation}`);
                }
            }
        }
    };
</script>

By following these steps, the page info API can be integrated and used in the ASP.NET MVC PDF Viewer.

View Sample in GitHub