Download in Blazor SfPdfViewer Component
21 Jun 20231 minute to read
The SfPdfViewer supports downloading the loaded PDF file from the toolbar by default. You can enable or disable the download option by setting the EnableDownload
API.
@using Syncfusion.Blazor.SfPdfViewer
<SfPdfViewer2 Width="100%" Height="100%" DocumentPath="@DocumentPath" EnableDownload="true" />
@code{
public string DocumentPath { get; set; } = "wwwroot/Data/PDF_Succinctly.pdf";
}
@using Syncfusion.Blazor.Buttons
@using Syncfusion.Blazor.SfPdfViewer
<SfButton OnClick="OnClick">Download</SfButton>
<SfPdfViewer2 Width="100%" Height="100%" DocumentPath="@DocumentPath" @ref="@Viewer" />
@code {
SfPdfViewer2 Viewer;
public string DocumentPath { get; set; } = "wwwroot/Data/PDF_Succinctly.pdf";
public async void OnClick(MouseEventArgs args)
{
await Viewer.DownloadAsync();
}
}
Download Filename
The DownloadFileName
property of the SfPdfViewer enables you to sets the name of the file to be downloaded.
The following code example shows how to set default filename to the downloaded file.
@using Syncfusion.Blazor.SfPdfViewer
<SfPdfViewer2 DocumentPath="@documentPath"
DownloadFileName="@downloadFileName"
Height="100%"
Width="100%">
</SfPdfViewer2>
@code
{
//Sets the PDF document path for initial loading.
public string documentPath { get; set; } = "wwwroot/Data/PDF_Succinctly.pdf";
//Sets the name of the file to be downloaded.
private string downloadFileName { get; set; } = "TOP-View_CutSheets.pdf";
}