« Learn about code sign… | Home | Tip of the day: DynaP… »

Tip of the day: DynaPDF form creation with calculation


Today I wrote the following example code for a client. This 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.
dim y as Double = 50 dim lines() as string lines.Append "var v1 = this.getField(""Val1"");" lines.Append "var v2 = this.getField(""Val2"");" lines.Append "var v3 = this.getField(""Val3"");" lines.Append "event.value = v1.value + v2.value + v3.value;" dim script as string = Join(lines, EndOfLine.UNIX) dim f as integer dim a as integer a = pdf.CreateJSAction(script) f = pdf.CreateTextField("Val1", -1, false, 0, 50.0, y, 200.0, 20.0) call pdf.SetTextFieldValue(f, "50.00", "50.00", pdf.ktaRight) call pdf.SetNumberFormat(f, pdf.kdsNoneDot, 2, pdf.knsMinusBlack, "", false) y = y + 30 f = pdf.CreateTextField("Val2", -1, true, 0, 50.0, y, 200.0, 20.0) call pdf.SetTextFieldValue(f, "100.00", "100.00", pdf.ktaRight) call pdf.SetNumberFormat(f, pdf.kdsNoneDot, 2, pdf.knsMinusBlack, "", false) y = y + 30 f = pdf.CreateTextField("Val3", -1, false, 0, 50.0, y, 200.0, 20.0) call pdf.SetTextFieldValue(f, "200.00", "200.00", pdf.ktaRight) call pdf.SetNumberFormat(f, pdf.kdsNoneDot, 2, pdf.knsMinusBlack, "", false) y = y + 30 f = pdf.CreateTextField("Sum", -1, false, 10, 50.0, y, 200.0, 20.0) call pdf.SetFieldBorderWidth(f, 0.0) call pdf.SetTextFieldValue(f, "350.00 €", "350.00 €", pdf.ktaRight) call pdf.SetFieldFlags(f, pdf.kffReadOnly, false) // This last field calculates sum of other fields // Works only in PDF Viewers supporting JavaScript! call pdf.AddActionToObj(pdf.kotField, pdf.koeOnCalc, a, f) call pdf.SetNumberFormat(f, pdf.kdsCommaDot, 2, pdf.knsMinusBlack, " €", false)
PS: Technically we could also offer this for our FileMaker Plugin if needed.
23 08 16 - 23:17
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.