Back to Devexpress

DxPdfViewer.DownloadAsync() Method

blazor-devexpress-dot-blazor-dot-pdfviewer-dot-dxpdfviewer-425b5bfe.md

latest3.3 KB
Original Source

DxPdfViewer.DownloadAsync() Method

Asynchronously downloads the document.

Namespace : DevExpress.Blazor.PdfViewer

Assembly : DevExpress.Blazor.PdfViewer.v25.2.dll

NuGet Package : DevExpress.Blazor.PdfViewer

Declaration

csharp
public Task DownloadAsync()

Returns

TypeDescription
Task

An asynchronous operation that downloads the document.

|

Remarks

Call the DownloadAsync() method to download the document. To specify the document name, use the DocumentName property.

The following code snippet removes all predefined commands from the PDF Viewer’s toolbar and adds two custom buttons:

  • The Print button invokes the Print dialog.
  • The Download button downloads the document.

razor
@using System.Reflection
@using DevExpress.Blazor.Reporting.Models

<DxPdfViewer @ref="pdfViewer"
             DocumentContent="@DocumentContent"
             DocumentName="Custom name"
             CustomizeToolbar="OnCustomizeToolbar" />

@code {
    DxPdfViewer pdfViewer { get; set; }
    byte[] DocumentContent { get; set; }

    protected override async Task OnInitializedAsync() {
        Assembly assembly = Assembly.GetExecutingAssembly();
        Stream stream = assembly.GetManifestResourceStream("Pdf.DataSources.Document.pdf");

        using (var binaryReader = new BinaryReader(stream)) {
            DocumentContent = binaryReader.ReadBytes((int)stream.Length);
        }
    }
    protected void OnCustomizeToolbar(ToolbarModel toolbarModel) {
        toolbarModel.AllItems.Clear();

        var printToolbarItem = new ToolbarItem {
            Text = "Print",
            AdaptiveText = "Print",
            BeginGroup = true,
            Id = "Print",
            IconCssClass = "print-btn",
            Click = async (args) => {
                await pdfViewer.PrintAsync();
            }
        };

        var downloadToolbarItem = new ToolbarItem {
            Text = "Download",
            AdaptiveText = "Download",
            BeginGroup = true,
            Id = "Download",
            IconCssClass = "download-btn",
            Click = async (args) => {
                await pdfViewer.DownloadAsync();
            }
        };
        toolbarModel.AllItems.Add(printToolbarItem);
        toolbarModel.AllItems.Add(downloadToolbarItem);
    }
}
css
.print-btn {
    mask-image: url(/images/printer.svg);
    mask-repeat: no-repeat;
    mask-size: 100%;
    background-color: currentColor;
    --toolbar-icon-size: 25px;
}

.download-btn {
    mask-image: url(/images/download.svg);
    mask-repeat: no-repeat;
    mask-size: 100%;
    background-color: currentColor;
    --toolbar-icon-size: 25px;
}

See Also

DxPdfViewer Class

DxPdfViewer Members

DevExpress.Blazor.PdfViewer Namespace