diff options
Diffstat (limited to 'src/workersrc.js')
-rw-r--r-- | src/workersrc.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/workersrc.js b/src/workersrc.js index ea1a889..240f037 100644 --- a/src/workersrc.js +++ b/src/workersrc.js @@ -28,6 +28,12 @@ import redirectIfNotIframe from './utils/redirectIfNotIframe' // Checks if the page is displayed in an iframe. If not redirect to /. redirectIfNotIframe() +// Retrieve the canDownload from the url, this is +// the most easy way to pass the prop to this iframe +const queryString = window.location.search +const urlParams = new URLSearchParams(queryString) +const canDownload = urlParams.get('canDownload') + // When "PDFViewerApplication.webViewerInitialized" is executed (once // "PDFViewerApplication.initialize" is done) it opens the PDF file via URL, // which requires the PDFViewerApplication to be properly configured, so the @@ -45,6 +51,43 @@ function initializeCustomPDFViewerApplication() { PDFViewerApplicationOptions.set('cMapUrl', document.getElementsByTagName('head')[0].getAttribute('data-cmapurl')) PDFViewerApplicationOptions.set('enablePermissions', true) + if (canDownload === '0') { + const pdfViewer = window.document.querySelector('.pdfViewer') + + if (pdfViewer) { + pdfViewer.classList.add('disabledTextSelection') + } + + if (PDFViewerApplication) { + // 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() { + } + } + + logger.info('Download, print and user interaction disabled') + } else { + logger.info('Download and print available') + } + logger.debug('Initialized files_pdfviewer', PDFViewerApplicationOptions.getAll()) } |