EDOM Posted July 6, 2020 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
Sherzod Posted July 6, 2020 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
Sherzod Posted July 6, 2020 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
EDOM Posted July 7, 2020 Author 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
EDOM Posted July 7, 2020 Author 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
Sherzod Posted July 7, 2020 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
Sherzod Posted July 7, 2020 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
Sherzod Posted July 7, 2020 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
EDOM Posted July 9, 2020 Author 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
Sherzod Posted July 9, 2020 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
EDOM Posted July 10, 2020 Author 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
Sherzod Posted July 10, 2020 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
EDOM Posted July 15, 2020 Author 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
loQsoft Posted March 9, 2024 Posted March 9, 2024 Hi! It is possible disable ? - Print button - Download button or how can i disable buttons ? Best Regards, Quote
Sherzod Posted March 9, 2024 Posted March 9, 2024 2 hours ago, loQsoft said: It is possible disable ? - Print button - Download button Hello, This post may help you: 1 Quote
loQsoft Posted May 25, 2024 Posted May 25, 2024 Hello! @Sherzod How can I understand that the print button has been pressed? I want to record that when the Print button is pressed, the PDF document is printed. It is possible? Best Regards, Quote
Sherzod Posted May 26, 2024 Posted May 26, 2024 5 hours ago, loQsoft said: How can I understand that the print button has been pressed? Hello, If I understand correctly, you want to know whether the print button on the toolbar was pressed? 1 Quote
Sherzod Posted May 28, 2024 Posted May 28, 2024 27 minutes ago, loQsoft said: Yes, exactly, you are right. But, as you know, this does not give 100 percent confidence that the user has printed, since he can cancel the printing. Quote
loQsoft Posted May 28, 2024 Posted May 28, 2024 you are right @Sherzod i know. i need just to know whether the print button on the toolbar was pressed Best Regards, Quote
Sherzod Posted May 29, 2024 Posted May 29, 2024 6 hours ago, loQsoft said: i know. i need just to know whether the print button on the toolbar was pressed Hello, By the way, this seems to be what you need or not? On 7/10/2020 at 9:28 AM, 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; Quote
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.