diff options
-rw-r--r-- | css/viewer.css | 21 | ||||
-rw-r--r-- | js/previewplugin.js | 5 | ||||
-rw-r--r-- | js/workersrc.js | 25 |
3 files changed, 47 insertions, 4 deletions
diff --git a/css/viewer.css b/css/viewer.css index eca5f53..9d4594c 100644 --- a/css/viewer.css +++ b/css/viewer.css @@ -21,3 +21,24 @@ html .doorHangerRight:after { html .doorHangerRight:before { right: 53px!important; } + +/* Prevent printing from the browser when the download of a share is hidden. */ +@media print { + .pdfViewer.disabledTextSelection { + visibility: hidden; + display: none; + } +} + +/* Prevent text selection when the download of a share is hidden. */ +.pdfViewer.disabledTextSelection .textLayer { + user-select: none; + -moz-user-select: none; + -webkit-user-select: none; + -ms-user-select: none; +} + +/* Override text cursor in descendants. */ +.pdfViewer.disabledTextSelection .textLayer * { + cursor: default; +} diff --git a/js/previewplugin.js b/js/previewplugin.js index eb82a16..67835fe 100644 --- a/js/previewplugin.js +++ b/js/previewplugin.js @@ -81,10 +81,6 @@ var isSecureViewerAvailable = function () { // if a filelist is present, the PDF viewer can be closed to go back there $('#pdframe').load(function(){ var iframe = $('#pdframe').contents(); - if ($('#hideDownload').val() === 'true') { - iframe.find('.toolbarButton.download').hide() - iframe.find('.toolbarButton.print').hide() - } if ($('#fileList').length) { iframe.find('#secondaryToolbarClose').click(function() { @@ -105,6 +101,7 @@ var isSecureViewerAvailable = function () { var hideDownload = $('#hideDownload').val(); if (hideDownload === 'true') { iframe.find('.download').addClass('hidden'); + iframe.find('.pdfViewer').addClass('disabledTextSelection') } }); diff --git a/js/workersrc.js b/js/workersrc.js index 1c9b4f0..b9c8e2c 100644 --- a/js/workersrc.js +++ b/js/workersrc.js @@ -70,6 +70,31 @@ function initializeCustomPDFViewerApplication() { this.downloadManager.downloadUrl(url, getPDFFileNameFromURL(url)); }; + + var hideDownload = window.parent.document.getElementById('hideDownload').value === 'true'; + if (hideDownload) { + // Disable download function when downloads are hidden, as even if the + // buttons in the UI are hidden the download could still be triggered + // with Ctrl|Meta+S. + PDFViewerApplication.download = function() { + } + + // Disable printing service when downloads are hidden, as even if the + // buttons in the UI are hidden the printing could still be triggered + // with Ctrl|Meta+P. + // Abuse the "supportsPrinting" parameter, which signals that the + // browser does not fully support printing, to make PDFViewer disable + // the printing service. + // "supportsPrinting" is a getter function, so it needs to be deleted + // before replacing it with a simple value. + delete PDFViewerApplication.supportsPrinting; + PDFViewerApplication.supportsPrinting = false; + // When printing is not supported a warning is shown by the default + // "beforePrint" function when trying to print. That function needs to + // be replaced with an empty one to prevent that warning to be shown. + PDFViewerApplication.beforePrint = function() { + } + } } document.addEventListener('webviewerloaded', initializeCustomPDFViewerApplication, true); |