Jump to content

Recommended Posts

Posted

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;

Posted
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;

 

  • Like 1
Posted
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;

 

  • Like 2
Posted
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!

  • Like 1
Posted

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.

 

Posted
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.

Posted
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.

Posted
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;

 

Posted
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();
            }

        });
    };     

Posted
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...

  • Like 1
Posted
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.

Posted

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;

 

  • Like 1
Posted
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!

  • Like 1
  • 3 years later...
  • 2 months later...
Posted

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,

 

Posted
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?

  • Like 1
Posted
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.

Posted
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;

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...