Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Create Fields with JavaScript Actions
Function:
Required plugins for this example: MBS DynaPDF Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Create Fields with JavaScript Actions
This example is the version from Mon, 3rd May 2020.
Project "Create Fields with JavaScript Actions.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu5 = ""
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu4 = ""
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = ""
End MenuBar
Class App Inherits Application
EventHandler Sub Open() Dim pdf As New MyDynapdfMBS dim d as new date Dim fi As FolderItem = SpecialFolder.Desktop.Child("Create Fields with JavaScript Actions.pdf") pdf.SetLicenseKey "Lite" // For this example you can use a Lite, Pro or Enterprise License call pdf.CreateNewPDF fi // We want to use top-down coordinates call pdf.SetPageCoords pdf.kpcTopDown call pdf.SetCompressionLevel(0) // so we can read in text editor // we try a lot of actions here. The fields should show text once you triggered event Call pdf.Append Call pdf.SetFont("Helvetica", 0, 12) Dim y As Double = 50 If True Then // Catalog, Pages Dim a As Integer = pdf.CreateJSAction("try { this.getField('FieldOpen').value = 'Open'; } catch(e) { alert(e); }") Dim f As Integer = pdf.CreateTextField("FieldOpen", -1, False, 0, 50.0, y, 200.0, 20.0) Call pdf.AddActionToObj(pdf.kotPage, pdf.koeOnOpen, a, 1) Call pdf.WriteText 260, y, "Open" y = y + 30 End If If True Then // Pages only Dim a As Integer = pdf.CreateJSAction("try { this.getField('FieldClose').value = 'Close'; } catch(e) { alert(e); }") Dim f As Integer = pdf.CreateTextField("FieldClose", -1, False, 0, 50.0, y, 200.0, 20.0) Call pdf.AddActionToObj(pdf.kotPage, pdf.koeOnClose, a, 1) Call pdf.WriteText 260, y, "Close" y = y + 30 End If If True Then // All fields, page, link annotations, bookmarks Dim a As Integer = pdf.CreateJSAction("try { this.getField('FieldMouseUp').value = 'MouseUp'; } catch(e) { alert(e); }") Dim f As Integer = pdf.CreateTextField("FieldMouseUp", -1, False, 0, 50.0, y, 200.0, 20.0) Call pdf.AddActionToObj(pdf.kotField, pdf.koeOnMouseUp, a, f) Call pdf.WriteText 260, y, "MouseUp" y = y + 30 End If If True Then // Form fields only Dim a As Integer = pdf.CreateJSAction("try { this.getField('FieldMouseEnter').value = 'MouseEnter'; } catch(e) { alert(e); }") Dim f As Integer = pdf.CreateTextField("FieldMouseEnter", -1, False, 0, 50.0, y, 200.0, 20.0) Call pdf.AddActionToObj(pdf.kotField, pdf.koeOnMouseEnter, a, f) Call pdf.WriteText 260, y, "MouseEnter" y = y + 30 End If If True Then // Form fields only Dim a As Integer = pdf.CreateJSAction("try { this.getField('FieldMouseExit').value = 'MouseExit'; } catch(e) { alert(e); }") Dim f As Integer = pdf.CreateTextField("FieldMouseExit", -1, False, 0, 50.0, y, 200.0, 20.0) Call pdf.AddActionToObj(pdf.kotField, pdf.koeOnMouseExit, a, f) Call pdf.WriteText 260, y, "MouseExit" y = y + 30 End If If True Then // Form fields only Dim a As Integer = pdf.CreateJSAction("try { this.getField('FieldMouseDown').value = 'MouseDown'; } catch(e) { alert(e); }") Dim f As Integer = pdf.CreateTextField("FieldMouseDown", -1, False, 0, 50.0, y, 200.0, 20.0) Call pdf.AddActionToObj(pdf.kotField, pdf.koeOnMouseDown, a, f) Call pdf.WriteText 260, y, "MouseDown" y = y + 30 End If If True Then // Form fields only Dim a As Integer = pdf.CreateJSAction("try { this.getField('FieldFocus').value = 'Focus'; } catch(e) { alert(e); }") Dim f As Integer = pdf.CreateTextField("FieldFocus", -1, False, 0, 50.0, y, 200.0, 20.0) Call pdf.AddActionToObj(pdf.kotField, pdf.koeOnFocus, a, f) Call pdf.WriteText 260, y, "Focus" y = y + 30 End If If True Then // Form fields only Dim a As Integer = pdf.CreateJSAction("try { this.getField('FieldBlur').value = 'Blur'; } catch(e) { alert(e); }") Dim f As Integer = pdf.CreateTextField("FieldBlur", -1, False, 0, 50.0, y, 200.0, 20.0) Call pdf.AddActionToObj(pdf.kotField, pdf.koeOnBlur, a, f) Call pdf.WriteText 260, y, "Blur" y = y + 30 End If If True Then // Text fields only Dim a As Integer = pdf.CreateJSAction("try { this.getField('FieldKeyStroke').value = 'KeyStroke'; } catch(e) { alert(e); }") Dim f As Integer = pdf.CreateTextField("FieldKeyStroke", -1, False, 0, 50.0, y, 200.0, 20.0) Call pdf.AddActionToObj(pdf.kotField, pdf.koeOnKeyStroke, a, f) Call pdf.WriteText 260, y, "KeyStroke" y = y + 30 End If If True Then // Text fields only Dim a As Integer = pdf.CreateJSAction("try { this.getField('FieldFormat').value = 'Format'; } catch(e) { alert(e); }") Dim f As Integer = pdf.CreateTextField("FieldFormat", -1, False, 0, 50.0, y, 200.0, 20.0) Call pdf.AddActionToObj(pdf.kotField, pdf.koeOnFormat, a, f) Call pdf.WriteText 260, y, "Format" y = y + 30 End If If True Then // Text fields only Dim a As Integer = pdf.CreateJSAction("try { this.getField('FieldCalc').value = 'Calc'; } catch(e) { alert(e); }") Dim f As Integer = pdf.CreateTextField("FieldCalc", -1, False, 0, 50.0, y, 200.0, 20.0) Call pdf.AddActionToObj(pdf.kotField, pdf.koeOnCalc, a, f) Call pdf.WriteText 260, y, "Calc" y = y + 30 End If If True Then // Text fields only Dim a As Integer = pdf.CreateJSAction("try { this.getField('FieldValidate').value = 'Validate'; } catch(e) { alert(e); }") Dim f As Integer = pdf.CreateTextField("FieldValidate", -1, False, 0, 50.0, y, 200.0, 20.0) Call pdf.AddActionToObj(pdf.kotField, pdf.koeOnValidate, a, f) Call pdf.WriteText 260, y, "Validate" y = y + 30 End If call pdf.EndPage call pdf.CloseFile fi.Launch Quit End EventHandler
End Class
Class MyDynaPDFMBS Inherits DynaPDFMBS
EventHandler Function Error(ErrorCode as integer, ErrorMessage as string, ErrorType as integer) As integer // output all messages on the console: System.DebugLog str(ErrorCode)+": "+ErrorMessage // and display dialog: Dim d as New MessageDialog //declare the MessageDialog object Dim b as MessageDialogButton //for handling the result d.icon=MessageDialog.GraphicCaution //display warning icon d.ActionButton.Caption="Continue" d.CancelButton.Visible=True //show the Cancel button // a warning or an error? if BitAnd(ErrorType, me.kE_WARNING) = me.kE_WARNING then // if user decided to ignore, we'll ignore if IgnoreWarnings then Return 0 d.Message="A warning occurred while processing your PDF code." // we add a third button to display all warnings d.AlternateActionButton.Caption = "Ignore warnings" d.AlternateActionButton.Visible = true else d.Message="An error occurred while processing your PDF code." end if d.Explanation = str(ErrorCode)+": "+ErrorMessage b=d.ShowModal //display the dialog Select Case b //determine which button was pressed. Case d.ActionButton Return 0 // ignore Case d.AlternateActionButton IgnoreWarnings = true Return 0 // ignore Case d.CancelButton Return -1 // stop End select End EventHandler
Property IgnoreWarnings As Boolean
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS DynaPDF Plugin.

The biggest plugin in space...




Links
MBS FileMaker blog