# HG changeset patch # User Alain Mazy # Date 1727958194 -7200 # Node ID 0a2b450cec3a655301c656bd61a02b38ce4bfad4 # Parent 4f224edac3481c81372aa27c1dfb517c669ef6f3 Added a Print button in the PDF viewer toolbar diff -r 4f224edac348 -r 0a2b450cec3a Applications/StoneWebViewer/NEWS --- a/Applications/StoneWebViewer/NEWS Thu Oct 03 09:53:54 2024 +0200 +++ b/Applications/StoneWebViewer/NEWS Thu Oct 03 14:23:14 2024 +0200 @@ -2,7 +2,7 @@ =============================== * Remember the previous layout when re-opening the viewer. - +* Added a Print button in the PDF viewer toolbar. Version 2.6 (2024-08-31) ======================== diff -r 4f224edac348 -r 0a2b450cec3a Applications/StoneWebViewer/WebApplication/index.html --- a/Applications/StoneWebViewer/WebApplication/index.html Thu Oct 03 09:53:54 2024 +0200 +++ b/Applications/StoneWebViewer/WebApplication/index.html Thu Oct 03 14:23:14 2024 +0200 @@ -923,6 +923,10 @@ data-toggle="tooltip" data-title="Show next page"> + diff -r 4f224edac348 -r 0a2b450cec3a Applications/StoneWebViewer/WebApplication/pdf-viewer.js --- a/Applications/StoneWebViewer/WebApplication/pdf-viewer.js Thu Oct 03 09:53:54 2024 +0200 +++ b/Applications/StoneWebViewer/WebApplication/pdf-viewer.js Thu Oct 03 14:23:14 2024 +0200 @@ -92,6 +92,29 @@ }); }, methods: { + Print: function() { + if (this.pdfDoc !== null) { + if (0) { // works on Chrome but with a popup that is blocked by default ! + const blob = new Blob([this.pdf], { type: 'application/pdf'}); + const blobUrl = URL.createObjectURL(blob); + + let w = window.open(blobUrl, '_blank'); + w.print(); + } else { + // Let's open a new window with the pdf + // First we need to convert the pdf from a byte array to a binary string and then to b64 + let binaryStringPdf = ''; + for (let i = 0; i < this.pdf.length; i++) { + binaryStringPdf += String.fromCharCode(this.pdf[i]); + } + + const htmlContent = ''; + + let w = window.open('', '_blank'); + w.document.write(htmlContent); + } + } + }, NextPage: function() { if (this.pdfDoc !== null && this.currentPage < this.pdfDoc.numPages) {