From 8e9494d1c6d14c71f477d3b8a0c2715532068088 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 72f39e4a..e4904064 100644 --- a/src/views/PDFView.vue +++ b/src/views/PDFView.vue @@ -97,7 +97,6 @@ export default { if (this.isEditable) { this.$nextTick(() => { this.getDownloadElement().removeAttribute('hidden') - this.getEditorModeButtonsElement().removeAttribute('hidden') }) } }, @@ -112,10 +111,6 @@ export default { return this.getIframeDocument().getElementById('download') }, - getEditorModeButtonsElement() { - return this.getIframeDocument().getElementById('editorModeButtons') - }, - handleWebviewerloaded() { const PDFViewerApplicationOptions = this.$refs.iframe.contentWindow.PDFViewerApplicationOptions @@ -144,6 +139,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 dbd3e55c..6b66b7bf 100644 --- a/templates/viewer.php +++ b/templates/viewer.php @@ -310,7 +310,7 @@
-