Allow/Disallow scripts while running PDF

45 views
Skip to first unread message

Gowtham Lcs

unread,
Nov 13, 2019, 4:57:08 PM11/13/19
to PDFTron WebViewer
Hi Team,

We would like to get the consent from user before running the script embedded in PDF document while previewing the PDF. For, example now I am uploading the attached file and viewing the preview throws general browser alert, on pressing ok it starts running the script on the preview. 

But we would like to get the consent from user to run or stop the script further. Do we have any settings to control this behavior. Please share. Thanks. 


Regards,

Gowtham C

 

 

JavaScriptClock.pdf

Kristian Hein

unread,
Nov 14, 2019, 7:15:20 PM11/14/19
to pdfnet-w...@googlegroups.com

Hello,


You can use the following code in a config file:



var firstRun = true;
var allowJavaScript = false;
 
var onTriggered = Actions.JavaScript.prototype.onTriggered;
Actions.JavaScript.prototype.onTriggered = function(target, event) {
  if (firstRun) {
    firstRun = false;
    allowJavaScript = window.confirm('Allow document JavaScript?');
  }
  if (!allowJavaScript) {
    CoreControls.disableEmbeddedJavaScript();
    return;
  }
 
  onTriggered.apply(this, arguments);
};


This was done using https://www.pdftron.com/api/web/CoreControls.html#.disableEmbeddedJavaScript__anchor


See config file guide here: https://www.pdftron.com/documentation/web/guides/config-files/


Best Regards,

Kristian Hein

Developer - WebViewer

PDFTron Systems, Inc.

www.pdftron.com


CONFIDENTIALITY NOTICE: This message (and any attachment to it) is intended only for the use of the individual or entity to which it is addressed in the header, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. Any reproduction, distribution, modification or use of the contents of this message (and any attachment to it) by any individual or entity other than the intended recipient is prohibited. If you have received this communication in error, please notify us immediately and delete the original.


Reply all
Reply to author
Forward
0 new messages