Skip to content

Commit 1537d03

Browse files
committed
Fix disabled annotation edition in view only files
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 <danxuliu@gmail.com>
1 parent 94cd880 commit 1537d03

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/views/PDFView.vue

+4-5
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export default {
9797
if (this.isEditable) {
9898
this.$nextTick(() => {
9999
this.getDownloadElement().removeAttribute('hidden')
100-
this.getEditorModeButtonsElement().removeAttribute('hidden')
101100
})
102101
}
103102
},
@@ -112,10 +111,6 @@ export default {
112111
return this.getIframeDocument().getElementById('download')
113112
},
114113

115-
getEditorModeButtonsElement() {
116-
return this.getIframeDocument().getElementById('editorModeButtons')
117-
},
118-
119114
handleWebviewerloaded() {
120115
const PDFViewerApplicationOptions = this.$refs.iframe.contentWindow.PDFViewerApplicationOptions
121116

@@ -144,6 +139,10 @@ export default {
144139
// AnnotationMode.ENABLE value is 1 in PDF.js, which shows
145140
// forms, but does not allow to interact with them
146141
PDFViewerApplicationOptions.set('annotationMode', 1)
142+
143+
// AnnotationEditorType.DISABLE value is -1 in PDF.js, which
144+
// prevents editing annotations
145+
PDFViewerApplicationOptions.set('annotationEditorMode', -1)
147146
}
148147

149148
// PDFViewerApplication can not be set when the "webviewerloaded"

templates/viewer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@
310310

311311
<div class="verticalToolbarSeparator hiddenMediumView"></div>
312312

313-
<div id="editorModeButtons" class="splitToolbarButton toggled" role="radiogroup" hidden="true">
313+
<div id="editorModeButtons" class="splitToolbarButton toggled" role="radiogroup">
314314
<button id="editorFreeText" class="toolbarButton" disabled="disabled" title="Text" role="radio" aria-checked="false" aria-controls="editorFreeTextParamsToolbar" tabindex="34" data-l10n-id="editor_free_text2">
315315
<span data-l10n-id="editor_free_text2_label">Text</span>
316316
</button>
@@ -322,7 +322,7 @@
322322
</button>
323323
</div>
324324

325-
<div id="editorModeSeparator" class="verticalToolbarSeparator" hidden="true"></div>
325+
<div id="editorModeSeparator" class="verticalToolbarSeparator"></div>
326326

327327
<button id="secondaryToolbarToggle" class="toolbarButton" title="Tools" tabindex="48" data-l10n-id="tools" aria-expanded="false" aria-controls="secondaryToolbar">
328328
<span data-l10n-id="tools_label">Tools</span>

0 commit comments

Comments
 (0)