Button Object | DocumentJavaScript Object | Programming with Generator for COM-ActiveX

PDF Java Script

DynamicPDF allows you to specify JavaScript code at the document level as well as at the form field level for any PDF.

Document Level JavaScript

The Document object contains a list of all JavaScript for that particular PDF. This list is referenced using the Document’s JavaScripts property. The following code demonstrates adding a simple entry to the document level JavaScript for the PDF:

[ASP - VBScript]
Set MyDocument = Server.CreateObject( "DynamicPDF.Document" )
Set MyPage = MyDocument.AddPage()
MyDocument.AddDocumentJavaScript "Say Hi", "app.alert('Hello');" 

Form Level JavaScript

Form fields such as buttons can also be associated with a JavaScript action. Below is an example that demonstrates a button press executing a JavaScript "print" action:

[ASP - VBScript]
Set MyDocument = Server.CreateObject( "DynamicPDF.Document" )
MyDocument.Title = "Document JavaScript"
Set MyPage = MyDocument.AddPage()
Dim MyButton
Set MyButton = MyPage.AddButton( "Button Name", 75, 75, 100, 50 )
MyButton.SetJavaScriptAction "this.print({bUI: false, bSilent: true, bShrinkToFit: true});"
MyButton.BackgroundColor = "AliceBlue"
MyButton.Behavior = DPDF_Behavior_Push
MyButton.Label = "Push"

Calling Document Level JavaScript from a Form

[ASP - VBScript]
Set MyDocument = Server.CreateObject( "DynamicPDF.Document" )
MyDocument.Title = "Document JavaScript"
Set MyPage = MyDocument.AddPage()
MyDocument.AddDocumentJavaScript "Say Bye", "function bye(){app.alert('Good Bye')}"
Dim MyButton
Set MyButton = MyPage.AddButton( "Button Name", 75, 75, 100, 50 )
MyButton.SetJavaScriptAction "bye();"
MyButton.BackgroundColor = "AliceBlue"
MyButton.Behavior = DPDF_Behavior_Push
MyButton.Label = "Push"


For further reading on PDF JavaScript please refer to the Adobe’s Acrobat JavaScript Scripting Guide, http://partners.adobe.com/public/developer/en/acrobat/sdk/AcroJSGuide.pdf

See Also 

Button Object | DocumentJavaScript Object | Programming with Generator for COM-ActiveX