diff --git a/addons/im_livechat/static/src/legacy/public_livechat.js b/addons/im_livechat/static/src/legacy/public_livechat.js
index 46db2d8cd81..8a714e99cd2 100644
--- a/addons/im_livechat/static/src/legacy/public_livechat.js
+++ b/addons/im_livechat/static/src/legacy/public_livechat.js
@@ -3530,6 +3530,7 @@ odoo.define('im_livechat.legacy.mail.DocumentViewer', function (require) {
var core = require('web.core');
var Widget = require('web.Widget');
+var { hidePDFJSButtons } = require('@web/js/libs/pdfjs');
var QWeb = core.qweb;
@@ -3658,6 +3659,9 @@ var DocumentViewer = Widget.extend({
this.$('.o_viewer_content').html(QWeb.render('im_livechat.legacy.mail.DocumentViewer.Content', {
widget: this
}));
+ if (this.activeAttachment.fileType === 'application/pdf') {
+ hidePDFJSButtons(this.$('.o_viewer_content')[0]);
+ }
this.$('.o_viewer_img').on("load", _.bind(this._onImageLoaded, this));
this.$('[data-toggle="tooltip"]').tooltip({ delay: 0 });
this._reset();
diff --git a/addons/mail/static/src/components/attachment_viewer/attachment_viewer.js b/addons/mail/static/src/components/attachment_viewer/attachment_viewer.js
index bd2f3896c73..108006b14d3 100644
--- a/addons/mail/static/src/components/attachment_viewer/attachment_viewer.js
+++ b/addons/mail/static/src/components/attachment_viewer/attachment_viewer.js
@@ -5,6 +5,8 @@ import useShouldUpdateBasedOnProps from '@mail/component_hooks/use_should_update
import useStore from '@mail/component_hooks/use_store/use_store';
import { link } from '@mail/model/model_field_command';
+import { hidePDFJSButtons } from '@web/js/libs/pdfjs';
+
const { Component, QWeb } = owl;
const { useRef } = owl.hooks;
@@ -53,6 +55,10 @@ class AttachmentViewer extends Component {
* transformation on image visualisation.
*/
this._zoomerRef = useRef('zoomer');
+ /**
+ * Reference of the IFRAME node when the attachment is a PDF.
+ */
+ this._iframeViewerPdfRef = useRef('iframeViewerPdf');
/**
* Tracked translate transformations on image visualisation. This is
* not observed with `useStore` because they are used to compute zoomer
@@ -67,6 +73,7 @@ class AttachmentViewer extends Component {
mounted() {
this.el.focus();
this._handleImageLoad();
+ this._hideUnwantedPdfJsButtons();
document.addEventListener('click', this._onClickGlobal);
}
@@ -75,6 +82,7 @@ class AttachmentViewer extends Component {
*/
patched() {
this._handleImageLoad();
+ this._hideUnwantedPdfJsButtons();
}
willUnmount() {
@@ -169,6 +177,17 @@ class AttachmentViewer extends Component {
}
}
+ /**
+ * @see 'hidePDFJSButtons'
+ *
+ * @private
+ */
+ _hideUnwantedPdfJsButtons() {
+ if (this._iframeViewerPdfRef.el) {
+ hidePDFJSButtons(this._iframeViewerPdfRef.el);
+ }
+ }
+
/**
* Display the previous attachment in the list of attachments.
*
diff --git a/addons/mail/static/src/components/attachment_viewer/attachment_viewer.xml b/addons/mail/static/src/components/attachment_viewer/attachment_viewer.xml
index af0651291d9..e3c5ef1f312 100644
--- a/addons/mail/static/src/components/attachment_viewer/attachment_viewer.xml
+++ b/addons/mail/static/src/components/attachment_viewer/attachment_viewer.xml
@@ -46,7 +46,7 @@
-
+
diff --git a/addons/mail/static/src/js/document_viewer.js b/addons/mail/static/src/js/document_viewer.js
index 9ee815f9265..5325921bc5d 100644
--- a/addons/mail/static/src/js/document_viewer.js
+++ b/addons/mail/static/src/js/document_viewer.js
@@ -2,6 +2,7 @@
import core from 'web.core';
import Widget from 'web.Widget';
+import { hidePDFJSButtons } from '@web/js/libs/pdfjs';
var QWeb = core.qweb;
@@ -74,6 +75,15 @@ var DocumentViewer = Widget.extend({
this.modelName = 'ir.attachment';
this._reset();
},
+ /**
+ * Do some actions after the widget is appended to the DOM
+ * @override
+ */
+ setElement: function () {
+ const result = this._super(...arguments);
+ this._hidePdfButtonsIfPresent();
+ return result;
+ },
/**
* Open a modal displaying the active attachment
* @override
@@ -101,6 +111,15 @@ var DocumentViewer = Widget.extend({
// Private
//---------------------------------------------------------------------------
+ /**
+ * Hide some buttons in PDF.js
+ * @override
+ */
+ _hidePdfButtonsIfPresent: function () {
+ if (this.activeAttachment.mimetype === 'application/pdf') {
+ hidePDFJSButtons(this.el);
+ }
+ },
/**
* @private
*/
@@ -137,6 +156,7 @@ var DocumentViewer = Widget.extend({
widget: this
}));
this.$('.o_viewer_img').on("load", _.bind(this._onImageLoaded, this));
+ this._hidePdfButtonsIfPresent();
this.$('[data-toggle="tooltip"]').tooltip({delay: 0});
this._reset();
},
diff --git a/addons/web/__manifest__.py b/addons/web/__manifest__.py
index e0b615e1800..8c0329b4f0f 100644
--- a/addons/web/__manifest__.py
+++ b/addons/web/__manifest__.py
@@ -388,6 +388,7 @@ This module provides the core of the Odoo Web Client.
'web/static/src/js/libs/fullcalendar.js',
'web/static/src/js/libs/jquery.js',
'web/static/src/js/libs/underscore.js',
+ 'web/static/src/js/libs/pdfjs.js',
'web/static/src/js/libs/popper.js',
'web/static/src/js/libs/zoomodoo.js',
'web/static/src/js/libs/jSignatureCustom.js',
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index 77b7f5b7407..8a5c8a4e902 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -25,6 +25,7 @@ var view_dialogs = require('web.view_dialogs');
var field_utils = require('web.field_utils');
var time = require('web.time');
const {ColorpickerDialog} = require('web.Colorpicker');
+const { hidePDFJSButtons } = require('@web/js/libs/pdfjs');
let FieldBoolean = deprecatedFields.FieldBoolean;
@@ -2253,13 +2254,6 @@ var FieldPdfViewer = FieldBinaryFile.extend({
// Private
//--------------------------------------------------------------------------
- /**
- * @private
- * @param {DOMElement} iframe
- */
- _disableButtons: function (iframe) {
- $(iframe).contents().find('button#openFile').hide();
- },
/**
* @private
* @param {string} [fileURI] file URI if specified
@@ -2292,7 +2286,6 @@ var FieldPdfViewer = FieldBinaryFile.extend({
$iFrame.on('load', function () {
self.PDFViewerApplication = this.contentWindow.window.PDFViewerApplication;
- self._disableButtons(this);
});
if (this.mode === "readonly" && this.value) {
$iFrame.attr('src', this._getURI());
@@ -2309,6 +2302,7 @@ var FieldPdfViewer = FieldBinaryFile.extend({
$selectUpload.removeClass('o_hidden');
}
}
+ hidePDFJSButtons($iFrame[0]);
},
//--------------------------------------------------------------------------
diff --git a/addons/web/static/src/js/libs/pdfjs.js b/addons/web/static/src/js/libs/pdfjs.js
index 92c1e560001..015983fc5dc 100644
--- a/addons/web/static/src/js/libs/pdfjs.js
+++ b/addons/web/static/src/js/libs/pdfjs.js
@@ -1,5 +1,49 @@
+/** @odoo-module **/
+
+import config from 'web.config';
+
+/**
+ * Until we have our own implementation of the /web/static/lib/pdfjs/web/viewer.{html,js,css}
+ * (currently based on Firefox), this method allows us to hide the buttons that we do not want:
+ * * "Open File"
+ * * "Print" (Hidden on mobile)
+ * * "Download"
+ *
+ * @link https://mozilla.github.io/pdf.js/getting_started/
+ *
+ * @param {Element} rootElement
+ */
+export function hidePDFJSButtons(rootElement) {
+ const cssStyle = document.createElement("style");
+ cssStyle.rel = "stylesheet";
+ cssStyle.innerHTML = `button#secondaryDownload.secondaryToolbarButton, button#download.toolbarButton,
+button#secondaryOpenFile.secondaryToolbarButton, button#openFile.toolbarButton {
+display: none !important;
+}`;
+ if (config.device.isMobileDevice) {
+ cssStyle.innerHTML = `${cssStyle.innerHTML}
+button#secondaryPrint.secondaryToolbarButton, button#print.toolbarButton{
+display: none !important;
+}`;
+ }
+ const iframe = rootElement.tagName === 'IFRAME' ? rootElement : rootElement.querySelector('iframe');
+ if (iframe) {
+ if (!iframe.dataset.hideButtons) {
+ iframe.dataset.hideButtons = 'true';
+ iframe.addEventListener('load', event => {
+ if (iframe.contentDocument && iframe.contentDocument.head) {
+ iframe.contentDocument.head.appendChild(cssStyle);
+ }
+ });
+ }
+ } else {
+ console.warn('No IFRAME found');
+ }
+}
+
/*
-* There is no changes to pdf.js in this file, but only a note about a change that has been done in it.
+* List of changes made in the library
+* There is no changes to pdf.js in this section, but only a note about changes that has been done in /web/static/lib/pdfjs/.
*
* In the module account_invoice_extract, the the code need to react to the 'pagerendered' event triggered by
* pdf.js. However in recent version of pdf.js, event are not visible outside of the library, except if the