The PDF form class gives access to AcroFields in a PDF.

1 Fullfill a form

The following example opens a PDF as a form, iterates on it's fields and performs update on it's values. Finally, writes back the new document.

Copy
<script>
    var form = new Ax.pdf.Form(new Ax.net.URL('https://bitbucket.org/deister/axional-docs-resources/raw/master/PDF/forms/FormExample.pdf'));
    
    console.log(form.getFields());

    var idx = 0;
    
    // Iterate on each field
    for (var fieldName of form.getFields()) {
        var fieldValue = form.getFieldValue(fieldName);

        console.log(form.getFieldType(fieldName) + " : " + fieldName + "=" + fieldValue);
    
        // check field type
        switch (form.getFieldType(fieldName)) {
            case form.CHECKBOX:
                form.setFieldValue(fieldName, "Yes");
                break;
            case form.COMBO:
                form.setFieldValue(fieldName, "Brown");
                break;
            default:
                form.setFieldValue(fieldName, "f_" + idx);
        }
        idx++;
    }
    
    new Ax.io.File("/tmp/sample.pdf").write(form);
    // PDF is returned as a Blob
    return form;
</script>

2 Field types

You can use form constants to determine field types.

  • CHECKBOX
  • COMBO
  • LIST
  • NONE
  • PUSHBUTTON
  • RADIOBUTTON
  • SIGNATURE
  • TEXT