From 557885cc92426fa6230911459562e5568c1158ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Sat, 11 Jan 2025 05:45:39 +0100 Subject: [PATCH 1/2] Fix disabled annotation edition in view only files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a PDF file was shared without edit permissions the annotation editor buttons were hidden in the toolbar. Besides being a dirty trick, it only prevented creating new annotations, but not editing existing ones. Now the parameter "annotationEditorMode" of PDF.js set to "AnnotationEditorType.DISABLE" is used instead, which properly disables editing annotations and also takes care of removing the buttons from the toolbar if needed. Note that the editor mode separator is no longer hidden; it was hidden back in the day when edition was not supported yet in the PDF viewer, and once edition was added it should have been shown whenever the editor buttons were shown, but it was not the case. Now it is shown by default and hidden as needed by PDF.js itself when annotation edition is disabled. Signed-off-by: Daniel Calviño Sánchez --- src/views/PDFView.vue | 9 ++++----- templates/viewer.php | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/views/PDFView.vue b/src/views/PDFView.vue index 6d261436..77576a81 100644 --- a/src/views/PDFView.vue +++ b/src/views/PDFView.vue @@ -115,7 +115,6 @@ export default { if (this.isEditable) { this.$nextTick(() => { this.getDownloadElement().removeAttribute('hidden') - this.getEditorModeButtonsElement().removeAttribute('hidden') }) } }, @@ -130,10 +129,6 @@ export default { return this.getIframeDocument().getElementById('download') }, - getEditorModeButtonsElement() { - return this.getIframeDocument().getElementById('editorModeButtons') - }, - handleWebviewerloaded() { const PDFViewerApplicationOptions = this.$refs.iframe.contentWindow.PDFViewerApplicationOptions @@ -162,6 +157,10 @@ export default { // AnnotationMode.ENABLE value is 1 in PDF.js, which shows // forms, but does not allow to interact with them PDFViewerApplicationOptions.set('annotationMode', 1) + + // AnnotationEditorType.DISABLE value is -1 in PDF.js, which + // prevents editing annotations + PDFViewerApplicationOptions.set('annotationEditorMode', -1) } // PDFViewerApplication can not be set when the "webviewerloaded" diff --git a/templates/viewer.php b/templates/viewer.php index a1578379..24c0e265 100644 --- a/templates/viewer.php +++ b/templates/viewer.php @@ -303,7 +303,7 @@
-