Access file name

17 Feb 20221 minute to read

The PDF Viewer server library allows you to can access the filename of the loaded PDF document using the documentLoad and downloadEnd event. Using these events, we can access the filename while loading and downloading the PDF document.

The following steps are used to access the file name of loaded PDF document in PDF viewer control,

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

Step 2: Access file name using below code snippet,

@Html.EJS().PdfViewer("pdfviewer").ServiceUrl(VirtualPathUtility.ToAbsolute("~/PdfViewer/")).DocumentLoad("documentLoad").DownloadEnd("documentLoad").Render()

<script>
    function documentLoad(args) {
        var viewer = document.getElementById('pdfviewer').ej2_instances[0];
        viewer.fileName = "pdfsuccintly.pdf";
        console.log(args);
    }  
</script>

Download the sample how to access file name