changeset 2164:952674a812c2

Added a Download button in the PDF viewer toolbar
author Alain Mazy <am@orthanc.team>
date Thu, 03 Oct 2024 17:19:12 +0200
parents 0a2b450cec3a
children 8b21b1f43d0e
files Applications/StoneWebViewer/NEWS Applications/StoneWebViewer/WebApplication/index.html Applications/StoneWebViewer/WebApplication/pdf-viewer.js
diffstat 3 files changed, 27 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/NEWS	Thu Oct 03 14:23:14 2024 +0200
+++ b/Applications/StoneWebViewer/NEWS	Thu Oct 03 17:19:12 2024 +0200
@@ -3,6 +3,8 @@
 
 * Remember the previous layout when re-opening the viewer.
 * Added a Print button in the PDF viewer toolbar.
+* Added a Download button in the PDF viewer toolbar.
+ 
 
 Version 2.6 (2024-08-31)
 ========================
--- a/Applications/StoneWebViewer/WebApplication/index.html	Thu Oct 03 14:23:14 2024 +0200
+++ b/Applications/StoneWebViewer/WebApplication/index.html	Thu Oct 03 17:19:12 2024 +0200
@@ -898,6 +898,14 @@
 
         <div class="wv-overlay">
           <div class="wv-overlay-bottomleft wvPrintExclude">
+            <button class="btn btn-primary" @click="Download()"
+                    data-toggle="tooltip" data-title="Download">
+              <i class="fa fa-download"></i>
+            </button>
+            <button class="btn btn-primary" @click="Print()"
+                    data-toggle="tooltip" data-title="Print">
+              <i class="fa fa-print"></i>
+            </button>
             <button class="btn btn-primary" @click="FitWidth()"
                     data-toggle="tooltip" data-title="Fit page width">
               <i class="fas fa-text-width"></i>
@@ -923,10 +931,6 @@
                     data-toggle="tooltip" data-title="Show next page">
               <i class="fa fa-chevron-circle-right"></i>
             </button>
-            <button class="btn btn-primary" @click="Print()"
-                    data-toggle="tooltip" data-title="Print">
-              <i class="fa fa-print"></i>
-            </button>
           </div>
         </div>
       </div>
--- a/Applications/StoneWebViewer/WebApplication/pdf-viewer.js	Thu Oct 03 14:23:14 2024 +0200
+++ b/Applications/StoneWebViewer/WebApplication/pdf-viewer.js	Thu Oct 03 17:19:12 2024 +0200
@@ -92,6 +92,23 @@
     });
   },
   methods: {
+    Download: function() {
+      if (this.pdfDoc !== null) {
+        const blob = new Blob([this.pdf], { type: 'application/pdf'});
+        const blobUrl = URL.createObjectURL(blob);
+
+        const a = document.createElement('a');
+        a.href = blobUrl;
+        a.download = "report.pdf";
+
+        document.body.appendChild(a);
+        a.click();
+        document.body.removeChild(a);
+
+        // Revoke the object URL to free up memory
+        URL.revokeObjectURL(blobUrl);
+      }
+    },
     Print: function() {
       if (this.pdfDoc !== null) {
         if (0) { // works on Chrome but with a popup that is blocked by default !