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
FireFox with a frame blocker active for the same page 3 blocked items.
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.
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.
Related Topics
Webpack: Module Not Found: Error: Can't Resolve (With Relative Path)
Set Values in Input Type Date and Time in JavaScript
How to Pass 3 Parameters in Onclick Function .The Parameters Are Inside PHP Tag
How to Change the Font Color, Font Size, and Button Color in React
How to Use Aria-Expanded="True" to Change a CSS Property
Require(Img Path) Not Working/ Cannot Find Module "." Reactjs
How to Get Date Value from One Date Input Field and Put It to Other Date Field Using JavaScript
How to Submit an HTML Form Without Redirection
Scroll to Element from Typescript Code (Angular 5)
Jquery Validate Phone Number With With Regex
How to Hide Div When You Scroll to Bottom and Show It Again When Scroll Up to Top
Pass Input Tag Value to as Href Parameter
Stylesheet Not Loading Because Mime Type Is Text/Html
Trigger Event When Element Becomes Visible With Ngif