diff --git a/web/app.js b/web/app.js index dd1af8834383ba..c3ac203cef815a 100644 --- a/web/app.js +++ b/web/app.js @@ -198,6 +198,8 @@ const PDFViewerApplication = { _touchInfo: null, _isCtrlKeyDown: false, _nimbusDataPromise: null, + canDownload: true, + canPrint: true, // Called once when the document is loaded. async initialize(appConfig) { @@ -690,6 +692,13 @@ const PDFViewerApplication = { } else { throw new Error("Not implemented: run"); } + + if (!this.canDownload) { + this._hideDownloadButtons(); + } + if (!this.canPrint) { + this._hidePrintButtons(); + } }, get initialized() { @@ -875,6 +884,24 @@ const PDFViewerApplication = { } }, + /** + * @private + */ + _hidePrintButtons() { + const { toolbar, secondaryToolbar } = this.appConfig; + toolbar?.print.classList.add("hidden"); + secondaryToolbar?.printButton.classList.add("hidden"); + }, + + /** + * @private + */ + _hideDownloadButtons() { + const { toolbar, secondaryToolbar } = this.appConfig; + toolbar?.download.classList.add("hidden"); + secondaryToolbar?.downloadButton.classList.add("hidden"); + }, + /** * Closes opened PDF document. * @returns {Promise} - Returns the promise, which is resolved when all @@ -1092,6 +1119,9 @@ const PDFViewerApplication = { }, downloadOrSave(options = {}) { + if (!this.canDownload) { + return; + } if (this.pdfDocument?.annotationStorage.size > 0) { this.save(options); } else { @@ -1743,6 +1773,9 @@ const PDFViewerApplication = { }, beforePrint() { + if (!this.canPrint) { + return; + } this._printAnnotationStoragePromise = this.pdfScriptingManager .dispatchWillPrint() .catch(() => { @@ -1806,6 +1839,9 @@ const PDFViewerApplication = { }, afterPrint() { + if (!this.canPrint) { + return; + } if (this._printAnnotationStoragePromise) { this._printAnnotationStoragePromise.then(() => { this.pdfScriptingManager.dispatchDidPrint(); @@ -1835,6 +1871,9 @@ const PDFViewerApplication = { }, triggerPrinting() { + if (!this.canPrint) { + return; + } if (!this.supportsPrinting) { return; } @@ -2420,9 +2459,15 @@ function webViewerSwitchAnnotationEditorParams(evt) { PDFViewerApplication.pdfViewer.annotationEditorParams = evt; } function webViewerPrint() { + if (!PDFViewerApplication.canPrint) { + return; + } PDFViewerApplication.triggerPrinting(); } function webViewerDownload() { + if (!PDFViewerApplication.canDownload) { + return; + } PDFViewerApplication.downloadOrSave(); } function webViewerOpenInExternalApp() { diff --git a/web/viewer.js b/web/viewer.js index 3e2947f0fcf51a..67070a813365d3 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -179,6 +179,10 @@ function getViewerConfiguration() { ? document.getElementById("fileInput") : null, debuggerScriptPath: "./debugger.mjs", + canDownload: + new URLSearchParams(window.location.search).get("download") !== "0", + canPrint: + new URLSearchParams(window.location.search).get("download") !== "0", }; }