« Tip of the day: DynaP… | Home | Save the date for MBS… »

Tip of the day: DynaPDF form creation with calculation with FileMaker


And just after I wrote it for Xojo, we got a query to do the same in FileMaker. The following snippet creates four form fields. The last field is read only and has a calculation in javascript attached, so the PDF Viewer can calculate the sum of the three fields above. The example shows a second feature called number formats. The PDF Viewer can than format the number with the given number of digits, dot or comma as decimal or thousands separator and of course with a currency prefix/postfix.

 

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)] 

PS: Needs newer plugin. EMail me if you need it today, else wait for the next prerelease.

24 08 16 - 09:53
No comments

  
Remember personal info?

Emoticons / Textile


Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.