diff --git a/blazorbootstrap/Components/PdfViewer/PdfViewer.razor b/blazorbootstrap/Components/PdfViewer/PdfViewer.razor
index 6829314c7..543b9806c 100644
--- a/blazorbootstrap/Components/PdfViewer/PdfViewer.razor
+++ b/blazorbootstrap/Components/PdfViewer/PdfViewer.razor
@@ -36,6 +36,7 @@
Go to First Page
Go to Last Page
Reset Zoom
+ Download
diff --git a/blazorbootstrap/Components/PdfViewer/PdfViewer.razor.cs b/blazorbootstrap/Components/PdfViewer/PdfViewer.razor.cs
index 961c4c133..8d59fe9e4 100644
--- a/blazorbootstrap/Components/PdfViewer/PdfViewer.razor.cs
+++ b/blazorbootstrap/Components/PdfViewer/PdfViewer.razor.cs
@@ -225,6 +225,10 @@ private async Task ZoomOutAsync()
await PdfViewerJsInterop!.ZoomInOutAsync(objRef!, Id!, scale);
}
+ private async Task DownloadPdf()
+ {
+ await PdfViewerJsInterop!.DownloadPdfAsync(Url);
+ }
#endregion
#region Properties, Indexers
diff --git a/blazorbootstrap/Components/PdfViewer/PdfViewerJsInterop.cs b/blazorbootstrap/Components/PdfViewer/PdfViewerJsInterop.cs
index b049e0502..15ba1b6d9 100644
--- a/blazorbootstrap/Components/PdfViewer/PdfViewerJsInterop.cs
+++ b/blazorbootstrap/Components/PdfViewer/PdfViewerJsInterop.cs
@@ -1,4 +1,5 @@
-namespace BlazorBootstrap;
+
+namespace BlazorBootstrap;
public class PdfViewerJsInterop : JsInteropBase
{
@@ -58,5 +59,9 @@ public async Task ZoomInOutAsync(object objRef, string elementId, double scale)
await SafeInvokeVoidAsync("zoomInOut", objRef, elementId, scale);
}
+ public async Task DownloadPdfAsync(string fileUrl)
+ {
+ await SafeInvokeVoidAsync("downloadPdf", fileUrl);
+ }
#endregion
}
diff --git a/blazorbootstrap/wwwroot/blazor.bootstrap.pdf.js b/blazorbootstrap/wwwroot/blazor.bootstrap.pdf.js
index b899d4b15..2f6cd2efd 100644
--- a/blazorbootstrap/wwwroot/blazor.bootstrap.pdf.js
+++ b/blazorbootstrap/wwwroot/blazor.bootstrap.pdf.js
@@ -182,6 +182,14 @@ export function zoomInOut(dotNetHelper, elementId, scale) {
queueRenderPage(pdf, pdf.pageNum);
}
+export function downloadPdf(fileUrl) {
+ const link = document.createElement('a');
+ link.href = fileUrl;
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+}
+
// resize
// print
// download