Disable/Hide Download Button in Iframe on Default Pdf Viewer

How to disable the download button in ViewerJS?

This works for me:

HTML

<iframe id="iframe" src ="..." width="800" height="500" allowfullscreen webkitallowfullscreen></iframe>

JS

$('#iframe').ready(function() {
setTimeout(function() {
$('#iframe').contents().find('#download').remove();
}, 100);
});

Remove download button from odoo's pdf_viewer widget

You can override the _disableButtons function and hide the download button.

Example:

var basic_fields = require('web.basic_fields');

basic_fields.FieldPdfViewer.include({
_disableButtons: function (iframe) {
$(iframe).contents().find('button#download').hide();
// $(iframe).contents().find('button#secondaryDownload').hide();
this._super(iframe);
},
});

If you need to control the download button visibility using the context attribute, try the following code:

var basic_fields = require('web.basic_fields');
var Context = require('web.Context');

basic_fields.FieldPdfViewer.include({
_disableButtons: function (iframe) {
var self = this;
if (self.attrs.context) {
var context = new Context(self.attrs.context).eval();
if(!context.download) {
$(iframe).contents().find('button#download').hide();
// $(iframe).contents().find('button#secondaryDownload').hide();
}
}
this._super(iframe);
},
});

Edit:

Create an XML file with the following content and add it to the data entry in the manifest file:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="assets_backend" inherit_id="web.assets_backend" name="assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/module_name/static/src/js/pdf_viewser.js"></script>
</xpath>
</template>
</data>
</odoo>

Create pdf_viewser.js under static/src/js and add the above code:

odoo.define('module_name.PDFViewer', function (require) {
"use strict";

var basic_fields = require('web.basic_fields');

basic_fields.FieldPdfViewer.include({
_disableButtons: function (iframe) {
$(iframe).contents().find('button#download').hide();
// $(iframe).contents().find('button#secondaryDownload').hide();
this._super(iframe);
},
});

});

PDF tollbar without download button

Mozilla browsers have no problem with Iframe, but browsers are configured by users to their security preferences.

<iframe id="page2" height="50%" width="100%"src="http://africau.edu/images/default/sample.pdf#page=2"></iframe>
<iframe id="page1" height="50%" width="100%"src="http://africau.edu/images/default/sample.pdf#page=1"></iframe>

Same as the web page text and images, Audio or Video content, all pdfs are "Download first to view" does not matter if

  • A=Href
  • Embed
  • Iframe
  • Object (avoid as depreciated)
  • cUrl (Users direct get)

So why remove the button if its not showing in the frame due to any ad blocker or other user setting such as send downloads into external secured PDF viewer

Mozilla browser with pdf plugin or add-in or PDF extender same as Chrome/Edge

Sample Image 1

FireFox with a frame blocker active for the same page 3 blocked items.

Sample Image 2

If you wish to change the Iframe view you need to be the PDF viewer application, but there is no guarantee it is the one the user is viewing within.

Sample Image

Here is a demo of a browser viewer where the download and print buttons are removed. However Browsers need to allow the user to control their own view so I have also opened the download on the right in a companion viewer.
A PDF client cannot view a PDF unless it is Decrypted after a download thus their copy is available for view and edit.

Sample Image 3



Related Topics



Leave a reply



Submit