Mercurial > hg > orthanc-stone
comparison Applications/StoneWebViewer/WebApplication/pdf-viewer.js @ 2173:4596ad1b2aa4 dicom-sr
integration mainline->dicom-sr
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 22 Oct 2024 15:56:08 +0200 |
parents | 952674a812c2 |
children |
comparison
equal
deleted
inserted
replaced
2161:e65fe2e50fde | 2173:4596ad1b2aa4 |
---|---|
90 this.container.addEventListener('wheel', function(event) { | 90 this.container.addEventListener('wheel', function(event) { |
91 that.MouseWheel(event); | 91 that.MouseWheel(event); |
92 }); | 92 }); |
93 }, | 93 }, |
94 methods: { | 94 methods: { |
95 Download: function() { | |
96 if (this.pdfDoc !== null) { | |
97 const blob = new Blob([this.pdf], { type: 'application/pdf'}); | |
98 const blobUrl = URL.createObjectURL(blob); | |
99 | |
100 const a = document.createElement('a'); | |
101 a.href = blobUrl; | |
102 a.download = "report.pdf"; | |
103 | |
104 document.body.appendChild(a); | |
105 a.click(); | |
106 document.body.removeChild(a); | |
107 | |
108 // Revoke the object URL to free up memory | |
109 URL.revokeObjectURL(blobUrl); | |
110 } | |
111 }, | |
112 Print: function() { | |
113 if (this.pdfDoc !== null) { | |
114 if (0) { // works on Chrome but with a popup that is blocked by default ! | |
115 const blob = new Blob([this.pdf], { type: 'application/pdf'}); | |
116 const blobUrl = URL.createObjectURL(blob); | |
117 | |
118 let w = window.open(blobUrl, '_blank'); | |
119 w.print(); | |
120 } else { | |
121 // Let's open a new window with the pdf | |
122 // First we need to convert the pdf from a byte array to a binary string and then to b64 | |
123 let binaryStringPdf = ''; | |
124 for (let i = 0; i < this.pdf.length; i++) { | |
125 binaryStringPdf += String.fromCharCode(this.pdf[i]); | |
126 } | |
127 | |
128 const htmlContent = '<html><body style="margin: 0;"><embed width="100%" height="100%" src="data:application/pdf;base64,' + btoa(binaryStringPdf) + '" type="application/pdf" /></body></html>'; | |
129 | |
130 let w = window.open('', '_blank'); | |
131 w.document.write(htmlContent); | |
132 } | |
133 } | |
134 }, | |
95 NextPage: function() { | 135 NextPage: function() { |
96 if (this.pdfDoc !== null && | 136 if (this.pdfDoc !== null && |
97 this.currentPage < this.pdfDoc.numPages) { | 137 this.currentPage < this.pdfDoc.numPages) { |
98 this.QueueRenderPage(this.currentPage + 1); | 138 this.QueueRenderPage(this.currentPage + 1); |
99 } | 139 } |