Creating a PDF calculator

This walkthrough demonstrates how to calculate sum of two numbers and days between two dates. The files used in this walkthrough can be downloaded here: Calculator.doc and Calculator.pdf.

  1. Launch Microsoft Word. Add text boxes num1, num2, result, date1, date2 and days. Add push button calculate and calculate2. Make the document look like the screenshot below:

    Add PDF calculator text fields in Microsoft Word

  2. Add the following JavaScript to the Mouse Up trigger of the calculatebutton.

    var v1 = this.getField("num1").value;
    var v2 = this.getField("num2").value;

    this.getField("result").value = v1 + v2;

    Add a PDF action in Microsoft Word

    Add PDF Javascript in Microsoft Word

  3. Add the following JavaScript to the Mouse Up trigger of the calculate2 button.

    var v1 = this.getField("date1").value;
    var v2 = this.getField("date2").value;

    var d1 = new Date(v1);
    var d2 = new Date(v2);

    var days = Math.abs(d1.getTime() - d2.getTime()) / 1000 / 60 / 60 / 24;

    this.getField("days").value = days;

  4. Add the following JavaScript to the Keystroke trigger of both date1 and date2 fields.

    AFDate_KeystrokeEx("mm/dd/yyyy");

  5. Add the following JavaScript to the Format trigger of both date1 and date2 fields.

    AFDate_FormatEx("mm/dd/yyyy");

  6. Choose Export to PDF from CenoPDF menu to create the PDF file and open it in Adobe Reader.

    Open the PDF calculator form in Adobe Reader