(Legacy) Adobe Acrobat 9 Pro: PDF Forms: Inserting an Automatic Date Field

Last Updated

Note: This article is based on legacy software.

You may want to know the date that a user completes a form. You can insert a text field in your PDF form that will automatically insert the current date. This field uses a simple JavaScript at the page level. Adding an automatic date field is a two-step process: First you must add the Date field. Then, you must add the JavaScript to the Page Properties.

Inserting the Date Field

The date will appear as part of a text field.

  1. Open the PDF file that you will use the form for.

  2. From the Forms menu, select Add or Edit Fields...
    Adobe Acrobat 9 Pro enters Form Editing mode and the Forms toolbar appears.
    form editing

  3. Click Text Field Tool. text field tool
    HINT: The cursor changes to a cross hairs. The cross hairs allow you to align the field with the ruler, text, or another field.

  4. Position the cursor where you want the text field to begin.

  5. Click and drag the mouse until the text field reaches the desired size.

  6. Release the mouse button.
    The Field Name entry box appears.
    field name

  7. In the Field Name text box, type a name for the date field.
    EXAMPLE: Type Today.
    NOTE: The name that you assign will be used in the Javascript and must match.

  8. Click Show All Properties.
    The Text Field Properties dialog box appears.
    text field properties

  9. On the General tab, in the Common Properties section, select Read Only.
    An option is selected when a check appears in the box next to it.
    This is necessary for calculated fields such as a date.

  10. On the Format tab
    1. From the Select format category pull-down list, select Date.
    2. From the Date Options scroll box, select a date format option.
      NOTE: This representation of the date format will be used when adding the JavaScript. An example of the date format is shown below the list.

  11. Click Close.
    The date field is inserted.

Adding the JavaScript

The javascript is applied to the page. Therefore, you must be out of Form Editing mode.

  1. If you are not out of Form Editing mode, click Close Form Editing. close form editing

  2. From the Navigation pane, click Pages. pages
    The Pages pane opens.
    This action toggles between hiding and displaying the Pages pane.

  3. Right click the page thumbnail of your form that contains the Date field » select Page Properties...
    The Page Properties dialog box appears.

  4. Select the Actions tab.
    actions tab

  5. In the Add an Action section, from the Select Trigger pull-down list, select Page Open.

  6. From the Select Action pull-down list, select Run a JavaScript.

  7. Click Add...
    The JavaScript Editor dialog box appears.
    javascript editor

  8. Type the text shown here:
    var f = this.getField("Today");
    f.value = util.printd("mmm/d/yyyy", new Date());

    Improper spacing in the text may affect results.
    The field reference must match the name you assigned to the text box in step 7 of Inserting the Date Field.
    The date format must match the format you selected in step 10 of Inserting the Date Field.

  9. Click OK.

  10. Click OK.
    The JavaScript is added.

  11. From the file menu » select Save As...
    The Save As dialog box appears.

  12. Using the Save in pull-down list, select a save location.

  13. In the File name text box, type the file name.

  14. Click Save.
    The PDF is saved with the JavaScript programmed into it.