comparison Applications/StoneWebViewer/WebApplication/pdf-viewer.js @ 2163:0a2b450cec3a

Added a Print button in the PDF viewer toolbar
author Alain Mazy <am@orthanc.team>
date Thu, 03 Oct 2024 14:23:14 +0200
parents 16c01cc201e7
children 952674a812c2
comparison
equal deleted inserted replaced
2162:4f224edac348 2163:0a2b450cec3a
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 Print: function() {
96 if (this.pdfDoc !== null) {
97 if (0) { // works on Chrome but with a popup that is blocked by default !
98 const blob = new Blob([this.pdf], { type: 'application/pdf'});
99 const blobUrl = URL.createObjectURL(blob);
100
101 let w = window.open(blobUrl, '_blank');
102 w.print();
103 } else {
104 // Let's open a new window with the pdf
105 // First we need to convert the pdf from a byte array to a binary string and then to b64
106 let binaryStringPdf = '';
107 for (let i = 0; i < this.pdf.length; i++) {
108 binaryStringPdf += String.fromCharCode(this.pdf[i]);
109 }
110
111 const htmlContent = '<html><body style="margin: 0;"><embed width="100%" height="100%" src="data:application/pdf;base64,' + btoa(binaryStringPdf) + '" type="application/pdf" /></body></html>';
112
113 let w = window.open('', '_blank');
114 w.document.write(htmlContent);
115 }
116 }
117 },
95 NextPage: function() { 118 NextPage: function() {
96 if (this.pdfDoc !== null && 119 if (this.pdfDoc !== null &&
97 this.currentPage < this.pdfDoc.numPages) { 120 this.currentPage < this.pdfDoc.numPages) {
98 this.QueueRenderPage(this.currentPage + 1); 121 this.QueueRenderPage(this.currentPage + 1);
99 } 122 }