Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
12.2
12.3
12.4
12.5
13.0
13.1
13.2
13.3
13.4
13.5
Statistic
FMM
Blog
Adds an action to a PDF object.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
DynaPDF | 6.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameter | Description | Example |
---|---|---|
The PDF reference returned from DynaPDF.New. | ||
ObjectType | The type of object that should get the action. Can be Action, Annotation, Bookmark, Catalog, Field, Page or PageLink. |
"Field" |
ObjectEvent | Which event should trigger the action. Can be OnOpen, OnClose, OnMouseUp, OnMouseEnter, OnMouseExit, OnMouseDown, OnFocus, OnBlur, OnKeyStroke, OnFormat, OnCalc, OnValidate, OnPageVisible, OnPageInVisible, OnPageOpen, OnPageClose, OnBeforeClosign, OnBeforeSaving, OnAfterSaving, OnBeforePrinting or OnAfterPrinting. |
"OnCalc" |
Action Handle | The handle for the action. e.g. returned by DynaPDF.CreateJSAction. |
$action |
Object Handle | The object handle, e.g. a field number for a ObjectType = Field. | $o |
Returns OK or error.
See also AddActionToObj function in DynaPDF manual.
Create sum field:
Set Variable [$y; Value:50]
Set Variable [$script; Value:"var v1 = this.getField(\"Val1\");" & ¶ & "var v2 = this.getField(\"Val2\");" & ¶ & "var v3 = this.getField(\"Val3\");" & ¶ & "event.value = v1.value + v2.value + v3.value;"]
Set Variable [$script; Value:MBS( "Text.ReplaceNewline"; $script; 2)]
Set Variable [$a; Value:MBS( "DynaPDF.CreateJSAction"; $pdf; $script)]
#Create 1st field
Set Variable [$f; Value:MBS( "DynaPDF.CreateTextField"; $pdf; "Val1"; -1; 0; 0; 50; $y; 200; 20)]
Set Variable [$r; Value:MBS( "DynaPDF.SetTextFieldValue"; $pdf; $f; "50.00"; "50.00"; "Right")]
Set Variable [$r; Value:MBS( "DynaPDF.SetNumberFormat"; $pdf; $f; "NoneDot"; 2; "MinusBlack")]
#Create 2nd field
Set Variable [$y; Value:$y + 30]
Set Variable [$f; Value:MBS( "DynaPDF.CreateTextField"; $pdf; "Val2"; -1; 0; 0; 50; $y; 200; 20)]
Set Variable [$r; Value:MBS( "DynaPDF.SetTextFieldValue"; $pdf; $f; "100.00"; "100.00"; "Right")]
Set Variable [$r; Value:MBS( "DynaPDF.SetNumberFormat"; $pdf; $f; "NoneDot"; 2; "MinusBlack")]
#Create 3rd field
Set Variable [$y; Value:$y + 30]
Set Variable [$f; Value:MBS( "DynaPDF.CreateTextField"; $pdf; "Val3"; -1; 0; 0; 50; $y; 200; 20)]
Set Variable [$r; Value:MBS( "DynaPDF.SetTextFieldValue"; $pdf; $f; "200.00"; "200.00"; "Right")]
Set Variable [$r; Value:MBS( "DynaPDF.SetNumberFormat"; $pdf; $f; "NoneDot"; 2; "MinusBlack")]
#Create sum field
#This last field calculates sum of other fields
#Works only in PDF Viewers supporting JavaScript!
Set Variable [$y; Value:$y + 30]
Set Variable [$f; Value:MBS( "DynaPDF.CreateTextField"; $pdf; "Sum"; -1; 0; 10; 50; $y; 200; 20)]
Set Variable [$r; Value:MBS( "DynaPDF.SetFieldBorderWidth"; $pdf; $f; 0)]
Set Variable [$r; Value:MBS( "DynaPDF.SetTextFieldValue"; $pdf; $f; "350.00 €"; "350.00 €"; "Right")]
Set Variable [$r; Value:MBS( "DynaPDF.SetFieldFlags"; $pdf; $f; "ReadOnly"; 0)]
Set Variable [$r; Value:MBS( "DynaPDF.AddActionToObj"; $pdf; "Field"; "OnCalc"; $a; $f)]
Set Variable [$r; Value:MBS( "DynaPDF.SetNumberFormat"; $pdf; $f; "CommaDot"; 2; "MinusBlack"; " €"; 0)]
Create checkbox to confirm page and jump to next one:
Set Variable [ $f ; Value: MBS( "DynaPDF.CreateCheckBox"; $pdf; "OK"; "OK";0; -1; $PageWidth-150; $pageHeight-20; 15; 15 ) ]
# This is javascript from Adobe to go to next page You could substitute many of their examples
Set Variable [ $script ; Value: "this.pageNum++" ]
Set Variable [ $script ; Value: MBS( "Text.ReplaceNewline"; $script; 2 ) ]
Set Variable [ $a ; Value: MBS( "DynaPDF.CreateJSAction"; $pdf; $script ) ]
Set Variable [ $r ; Value: MBS( "DynaPDF.AddActionToObj"; $pdf; "Field"; "OnMouseUp"; $a; $f ) ]
Add JavaScript action for a link:
Set Variable [ $r ; Value: MBS( "DynaPDF.SetFont"; $pdf; "Helvetica"; "none"; 12) ]
Set Variable [ $r ; Value: MBS( "DynaPDF.SetTextRect"; $pdf; 310; 30; 200; 20) ]
Set Variable [ $r ; Value: MBS( "DynaPDF.SetStrokeColor"; $pdf; 0; 0; 0) ]
Set Variable [ $r ; Value: MBS( "DynaPDF.WriteFText"; $pdf; "center"; "Open MBS Website in new Tab") ]
# the page link points to the page to go for if no JavaScript is enabled
// Set Variable [ $LinkRef ; Value: MBS( "DynaPDF.PageLink"; $pdf; 310; 10; 200; 20; 2) ]
# the web link points to the URL to use when no JavaScript is enabled
Set Variable [ $LinkRef ; Value: MBS( "DynaPDF.WebLink"; $pdf; 310; 10; 200; 20; "https://www.monkeybreadsoftware.com/filemaker/") ]
# we add a JavaScript action to open URL
Set Variable [ $JSAction ; Value: MBS( "DynaPDF.CreateJSAction"; $PDF; "app.launchURL(\"https://www.monkeybreadsoftware.com/filemaker/\", true);" ) ]
Set Variable [ $r ; Value: MBS( "DynaPDF.AddActionToObj"; $pdf; "PageLink"; "OnMouseUp"; $JSAction; $LinkRef; ) ]
Set Variable [ $r ; Value: MBS( "DynaPDF.EndPage"; $pdf) ]
This function checks for a license.
Created 24th August 2016, last changed 21st April 2023