How to Control File Downloads in ASP.NET Core PDF Viewer
14 Aug 20262 minutes to read
Intercept PDF downloads and apply custom logic using the downloadStart event. Set args.cancel = true to prevent the download from proceeding. By default, args.cancel is false, allowing downloads to proceed.
Use the downloadStart event to implement custom authorization or validation rules before allowing downloads based on the application requirements.
<div style="width:100%;height:600px">
<ejs-pdfviewer id="pdfviewer"
style="height:600px"
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
downloadStart="downloadStart">
</ejs-pdfviewer>
</div>
<script>
function downloadStart(args) {
// Apply custom logic to allow or deny downloads
args.cancel = true; // Prevent download action
}
</script><div style="width:100%;height:600px">
<ejs-pdfviewer id="pdfviewer"
style="height:600px"
serviceUrl="/Index"
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
downloadStart="downloadStart">
</ejs-pdfviewer>
</div>
<script>
function downloadStart(args) {
// Apply custom logic to allow or deny downloads
args.cancel = true; // Prevent download action
}
</script>