Skip to main content
Participant
October 11, 2017
Answered

insert page includes document javascripts - what about document actions ?

  • October 11, 2017
  • 1 reply
  • 488 views

I have used insert page from a document containing document level javascripts.

This loads the document level javascripts into a new PDF which is a great way for users I support to add special functionality into their documents.

The latest example is a JS that adds a date/time stamp as a button to the footer of each page. The requirement is however that this be triggered on the WillPrint document action. Unfortunately document actions do not seem to be respected in the new PDF from the imported PDF.

I have tried adding this as a document level JS without the function wrapper but it does not set the trigger in the document

this.setAction({cTrigger: "WillPrint", cScript: addDateStamp});

Any suggestions that will allow for adding the functionality to the PDF without the user having to manually edit or add document actions...

Thanks

Ben

This topic has been closed for replies.
Correct answer flexstone

I was able to work this out with the following document JS

var myadddatestamp='var inch = 72;\r'

+ 'var monthNames = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");\r'

+ 'var d = new Date();\r'

+ 'var day = util.printd("dd",d);\r'

+ 'var m = util.printd("m",d);\r'

+ 'var yr = util.printd("yy",d);\r'

+ 'var h = d.getHours();\r'

+ 'var M = d.getMinutes();\r'

+ 'var s = d.getSeconds();\r'

+ 'var f = this.getField("thisday");\r'

+ 'var printdate = "Printed " + day + "-" + monthNames + "-" + yr + " at " + h+":" + M +":"+s;\r'

+ 'printdate += "      This copy expires at 23:59 on the last day of the month";\r'

+ 'if(f){\r'

+ '    f.buttonSetCaption(printdate)\r'

+ '}\r'

+ 'else{\r'

+ 'for (var p = 0; p < this.numPages; p++) {\r'

+ '    var aRect = this.getPageBox( {nPage: p} );\r'

+ '    aRect[0] = .5*inch;\r'

+ '    aRect[2] = .95*aRect[2];\r'

+ '    aRect[1] = 1.2*inch;\r'

+ '    aRect[3] = 1.45*inch;\r'

+ '    var fname = "thisday";\r'

+ '    var f = this.addField(fname, "button", p, aRect );\r'

+ '    f.borderStyle = border.s;\r'

+ '    f.textColor = ["RGB",1,1,1];\r'

+ '    f.fillColor = ["RGB",1,0.66,0.75];\r'

+ '    f.buttonSetCaption(printdate);}}\r'

this.setAction({cTrigger: "WillPrint", cScript: myadddatestamp});

1 reply

flexstoneAuthorCorrect answer
Participant
October 11, 2017

I was able to work this out with the following document JS

var myadddatestamp='var inch = 72;\r'

+ 'var monthNames = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");\r'

+ 'var d = new Date();\r'

+ 'var day = util.printd("dd",d);\r'

+ 'var m = util.printd("m",d);\r'

+ 'var yr = util.printd("yy",d);\r'

+ 'var h = d.getHours();\r'

+ 'var M = d.getMinutes();\r'

+ 'var s = d.getSeconds();\r'

+ 'var f = this.getField("thisday");\r'

+ 'var printdate = "Printed " + day + "-" + monthNames + "-" + yr + " at " + h+":" + M +":"+s;\r'

+ 'printdate += "      This copy expires at 23:59 on the last day of the month";\r'

+ 'if(f){\r'

+ '    f.buttonSetCaption(printdate)\r'

+ '}\r'

+ 'else{\r'

+ 'for (var p = 0; p < this.numPages; p++) {\r'

+ '    var aRect = this.getPageBox( {nPage: p} );\r'

+ '    aRect[0] = .5*inch;\r'

+ '    aRect[2] = .95*aRect[2];\r'

+ '    aRect[1] = 1.2*inch;\r'

+ '    aRect[3] = 1.45*inch;\r'

+ '    var fname = "thisday";\r'

+ '    var f = this.addField(fname, "button", p, aRect );\r'

+ '    f.borderStyle = border.s;\r'

+ '    f.textColor = ["RGB",1,1,1];\r'

+ '    f.fillColor = ["RGB",1,0.66,0.75];\r'

+ '    f.buttonSetCaption(printdate);}}\r'

this.setAction({cTrigger: "WillPrint", cScript: myadddatestamp});