EDOM Posted July 6, 2020 Share Posted July 6, 2020 It can hide Toolbar button(print/download) in FrameLoaded event but how can I prevent user use Ctrl+P to print and Ctrl+S to download PDF from UniPDFFrame procedure TUniFrame_Employee.UniPDFFrameFrameLoaded(Sender: TObject); begin //Hide download button UniSession.AddJS (UniPDFFrame_Cert.JSName + '.iframe.contentWindow.document.' + 'getElementById ("download").style.display = "none"'); UniSession.AddJS (UniPDFFrame_Cert.JSName + '.iframe.contentWindow.document.' + 'getElementById ("secondaryDownload").style.display = "none"'); // Hide print button UniSession.AddJS (UniPDFFrame_Cert.JSName + '.iframe.contentWindow.document.' + 'getElementById ("print").style.display = "none"'); UniSession.AddJS (UniPDFFrame_Cert.JSName + '.iframe.contentWindow.document.' + 'getElementById ("secondaryPrint").style.display = "none"'); end; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 6, 2020 Share Posted July 6, 2020 2 hours ago, EDOM said: how can I prevent user use Ctrl+P One possible solution: procedure TMainForm.UniPDFFrame1FrameLoaded(Sender: TObject); begin // Disable printing UniPDFFrame1.JSInterface.JSCode(#1'.iframe.contentWindow.print=Ext.emptyFn;'); end; 1 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 6, 2020 Share Posted July 6, 2020 3 hours ago, EDOM said: but how can I prevent user use Ctrl+P to print and Ctrl+S to download PDF from UniPDFFrame 1. UniPDFFrame1.ClientEvents.UniEvents -> function afterCreate(sender) { sender.disableKeysPrintSave = function() { // disable printing sender.iframe.contentWindow.print=Ext.emptyFn; // disable save $(sender.iframe.contentDocument).bind('keydown', function(e) { if (e.ctrlKey && (e.which == 83)) { e.preventDefault(); return false; } }); }; } 2. Usage: procedure TMainForm.UniPDFFrame1FrameLoaded(Sender: TObject); begin UniPDFFrame1.JSInterface.JSCall('disableKeysPrintSave', []); end; 2 Quote Link to comment Share on other sites More sharing options...
EDOM Posted July 7, 2020 Author Share Posted July 7, 2020 15 hours ago, Sherzod said: 1. UniPDFFrame1.ClientEvents.UniEvents -> function afterCreate(sender) { sender.disableKeysPrintSave = function() { // disable printing sender.iframe.contentWindow.print=Ext.emptyFn; // disable save $(sender.iframe.contentDocument).bind('keydown', function(e) { if (e.ctrlKey && (e.which == 83)) { e.preventDefault(); return false; } }); }; } 2. Usage: procedure TMainForm.UniPDFFrame1FrameLoaded(Sender: TObject); begin UniPDFFrame1.JSInterface.JSCall('disableKeysPrintSave', []); end; Hi Sherzod, It works, thank you for your kind assistance! 1 Quote Link to comment Share on other sites More sharing options...
EDOM Posted July 7, 2020 Author Share Posted July 7, 2020 Hi Sherzod, For security issue, I should keep logs when user have permission to download or print file How can I detect when user triggered download and print event in UniPDFFrame ? include clicked toolbar menu and use shortcut (Ctrl+P & Ctrl+S) Thank you very much and looking forward to hearing from you. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 7, 2020 Share Posted July 7, 2020 22 minutes ago, EDOM said: For security issue, I should keep logs when user have permission to download or print file How can I detect when user triggered download and print event in UniPDFFrame ? include clicked toolbar menu and use shortcut (Ctrl+P & Ctrl+S) Thank you very much and looking forward to hearing from you. Hi, Well, I think you can use Ctrl+S to track downloads. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 7, 2020 Share Posted July 7, 2020 1 minute ago, Sherzod said: Well, I think you can use Ctrl+S to track downloads. But there is also a button as you noted, also need to consider. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 7, 2020 Share Posted July 7, 2020 39 minutes ago, EDOM said: I should keep logs when user have permission to download I do not take into account the previous codes. 1. function afterCreate(sender) { var me = sender; me.saveLog = function() { console.log("Saved..."); //ajaxRequest... }; me.attachLogEvents = function() { me.iframe.contentDocument.getElementById('download').addEventListener('click', me.saveLog); me.iframe.contentDocument.getElementById('secondaryDownload').addEventListener('click', me.saveLog); $(me.iframe.contentDocument).bind('keydown', function(e) { if (e.ctrlKey && (e.which == 83)) { me.saveLog(); } }); }; } 2. procedure TMainForm.UniPDFFrame1FrameLoaded(Sender: TObject); begin (Sender as TUniPDFFrame).JSInterface.JSCall('attachLogEvents', []); end; Quote Link to comment Share on other sites More sharing options...
EDOM Posted July 9, 2020 Author Share Posted July 9, 2020 On 7/7/2020 at 5:51 PM, Sherzod said: I do not take into account the previous codes. 1. function afterCreate(sender) { var me = sender; me.saveLog = function() { console.log("Saved..."); //ajaxRequest... }; me.attachLogEvents = function() { me.iframe.contentDocument.getElementById('download').addEventListener('click', me.saveLog); me.iframe.contentDocument.getElementById('secondaryDownload').addEventListener('click', me.saveLog); $(me.iframe.contentDocument).bind('keydown', function(e) { if (e.ctrlKey && (e.which == 83)) { me.saveLog(); } }); }; } 2. procedure TMainForm.UniPDFFrame1FrameLoaded(Sender: TObject); begin (Sender as TUniPDFFrame).JSInterface.JSCall('attachLogEvents', []); end; Hi Sherzod, Thank you for the prompt reply. Your solution can handle Download & Ctrl+S event without problem. I try to add the events to Print & Ctrl+P but failed in Ctrl+P (click toolbar print button can detect) Could you please help to check on this issue. var me = sender; me.saveLog_download = function() { console.log("Download..."); //ajaxRequest... ajaxRequest(sender, "Download", ["action=dwonload"]); }; me.saveLog_print = function() { console.log("Print..."); //ajaxRequest... ajaxRequest(sender, "Print", ["action=print"]); }; me.attachLogEvents = function() { //Download me.iframe.contentDocument.getElementById('download').addEventListener('click', me.saveLog_download); me.iframe.contentDocument.getElementById('secondaryDownload').addEventListener('click', me.saveLog_download); //Print me.iframe.contentDocument.getElementById('print').addEventListener('click', me.saveLog_print); me.iframe.contentDocument.getElementById('secondaryPrint').addEventListener('click', me.saveLog_print); $(me.iframe.contentDocument).bind('keydown', function(e) { if (e.ctrlKey && (e.which == 80)) { //<-- didn't work me.saveLog_print(); } }); }; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 9, 2020 Share Posted July 9, 2020 2 hours ago, EDOM said: I try to add the events to Print & Ctrl+P but failed in Ctrl+P (click toolbar print button can detect) Could you please help to check on this issue. Hello, I will try to analyze for print too. But keep in mind, in any case, you cannot be sure that the user has printed the page, because he can open the print dialog and print, and also cancel printing... 1 Quote Link to comment Share on other sites More sharing options...
EDOM Posted July 10, 2020 Author Share Posted July 10, 2020 23 hours ago, Sherzod said: Hello, I will try to analyze for print too. But keep in mind, in any case, you cannot be sure that the user has printed the page, because he can open the print dialog and print, and also cancel printing... Hi Sherzod, Thank you for all the good advice you have given me. I am looking forward to hearing from you. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 10, 2020 Share Posted July 10, 2020 Hi, 50 minutes ago, EDOM said: Thank you for all the good advice you have given me. I am looking forward to hearing from you. Thank you. You can try this approach: procedure TMainForm.UniPDFFrame1FrameLoaded(Sender: TObject); begin (Sender as TUniPDFFrame).JSInterface.JSCode(#1'.iframe.contentWindow.onafterprint=function(){ajaxRequest('#1', "pdialogclosed", [])};'); end; procedure TMainForm.UniPDFFrame1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'pdialogclosed' then ShowMessage('pdialogclosed'); end; 1 Quote Link to comment Share on other sites More sharing options...
EDOM Posted July 15, 2020 Author Share Posted July 15, 2020 On 7/10/2020 at 12:28 PM, Sherzod said: You can try this approach: procedure TMainForm.UniPDFFrame1FrameLoaded(Sender: TObject); begin (Sender as TUniPDFFrame).JSInterface.JSCode(#1'.iframe.contentWindow.onafterprint=function(){ajaxRequest('#1', "pdialogclosed", [])};'); end; procedure TMainForm.UniPDFFrame1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'pdialogclosed' then ShowMessage('pdialogclosed'); end; Hi Sherzod, Thank you very much, it works perfectly! 1 Quote Link to comment Share on other sites More sharing options...
loQsoft Posted March 9 Share Posted March 9 Hi! It is possible disable ? - Print button - Download button or how can i disable buttons ? Best Regards, Quote Link to comment Share on other sites More sharing options...
Sherzod Posted March 9 Share Posted March 9 2 hours ago, loQsoft said: It is possible disable ? - Print button - Download button Hello, This post may help you: 1 Quote Link to comment Share on other sites More sharing options...
loQsoft Posted March 9 Share Posted March 9 Thank you very much @Sherzod Best Regards, 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.