Set Field Script

Set a field script

  1. Bind the source PDF to the FormEditor facade.
  2. Add an initial JavaScript action to the field.
  3. Replace it with the updated script text.
  4. Save the updated document.
public static void setFieldScript(Path inputFile, Path outputFile) {
    FormEditor editor = new FormEditor();
    try {
        editor.bindPdf(inputFile.toString());
        editor.addFieldScript("Script_Demo_Button", "app.alert('Script 1 has been executed');");
        editor.setFieldScript("Script_Demo_Button", "app.alert('Script 2 has been executed');");
        editor.save(outputFile.toString());
    } finally {
        editor.close();
    }
}