Skip to content

Commit

Permalink
Fix disabled annotation edition in view only files
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
danxuliu committed Jan 29, 2025
1 parent c74a7ef commit 57842d7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions js/files_pdfviewer-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files_pdfviewer-main.js.map

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions src/views/PDFView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export default {
if (this.isEditable) {
this.$nextTick(() => {
this.getDownloadElement().removeAttribute('hidden')
this.getEditorModeButtonsElement().removeAttribute('hidden')
})
}
},
Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions templates/viewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@

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

<div id="editorModeButtons" class="splitToolbarButton toggled" role="radiogroup" hidden="true">
<div id="editorModeButtons" class="splitToolbarButton toggled" role="radiogroup">
<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">
<span data-l10n-id="editor_free_text2_label">Text</span>
</button>
Expand All @@ -322,7 +322,7 @@
</button>
</div>

<div id="editorModeSeparator" class="verticalToolbarSeparator" hidden="true"></div>
<div id="editorModeSeparator" class="verticalToolbarSeparator"></div>

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

0 comments on commit 57842d7

Please sign in to comment.