Having trouble getting help?
Contact Support
Contact Support
Access file name
7 Sep 20231 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
@Html.EJS().PdfViewer("pdfviewer").DocumentPath("https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf").DocumentLoad("documentLoad").DownloadEnd("documentLoad").Render()
<script>
function documentLoad(args) {
var viewer = document.getElementById('pdfviewer').ej2_instances[0];
args.fileName = "pdfsuccintly.pdf";
//Sets the name of the file to be downloaded
viewer.downloadFileName = "pdfsuccintly.pdf";
console.log(args);
}
</script>
```
```html
@Html.EJS().PdfViewer("pdfviewer").DocumentPath("https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf").ServiceUrl(VirtualPathUtility.ToAbsolute("~/PdfViewer/")).DocumentLoad("documentLoad").DownloadEnd("documentLoad").Render()
<script>
function documentLoad(args) {
var viewer = document.getElementById('pdfviewer').ej2_instances[0];
args.fileName = "pdfsuccintly.pdf";
//Sets the name of the file to be downloaded
viewer.downloadFileName = "pdfsuccintly.pdf";
console.log(args);
}
</script>
```
Download the sample how to access file name