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" />

    public string DocumentPath { get; set; } = "wwwroot/Data/PDF_Succinctly.pdf";

Blazor SfPdfViewer with Download Option

@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"

    //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";


View sample in GitHub.

See also