Skip to content
ComPDF
Guides

Predefined Form Fields

Predefined form fields allow you to set default form properties that will be automatically applied when creating new form fields. You can set predefined form field properties through CPDFConfiguration or CPDFReaderWidgetController.

Here's an example of how to set predefined form field properties:

Setting Predefined Form Field Properties via CPDFConfiguration

dart
CPDFReaderWidget(
  document: widget.documentPath,
  configuration: CPDFConfiguration(
        formsConfig: const CPDFFormsConfig(
      initAttribute: CPDFFormAttribute(
        textFieldAttr: CPDFTextFieldAttr(
          fillColor: Colors.lightBlue,
          borderWidth: 10,
          fontSize: 20,
          borderColor: Colors.pink,
          fontColor: Colors.white,
          alignment: CPDFAlignment.right,
          familyName: 'Times',
          styleName: 'Bold'
        ),
        checkBoxAttr: CPDFCheckBoxAttr(
          fillColor: Colors.lightBlue,
          borderWidth: 8,
          borderColor: Colors.pink,
          checkedColor: Colors.deepOrange,
          isChecked: true,
          checkedStyle: CPDFCheckStyle.circle
        ),
        radioButtonAttr: CPDFRadioButtonAttr(
            fillColor: Colors.lightBlue,
            borderWidth: 8,
            borderColor: Colors.pink,
            checkedColor: Colors.deepOrange,
            isChecked: true,
            checkedStyle: CPDFCheckStyle.circle
        ),
        listBoxAttr: CPDFListBoxAttr(
          fillColor: Colors.lightBlue,
          borderWidth: 8,
          borderColor: Colors.pink,
          fontColor: Colors.white,
          familyName: 'Academy Engraved LET',
          styleName: 'Plain',
          fontSize: 20
        ),
      )
    )
  );

For more definable form field properties, please refer to the CPDFFormAttribute class definition.

Setting Predefined Form Field Properties via CPDFReaderWidgetController

dart
// Get the currently defined default form field attributes
CPDFFormAttribute defaultFormStyle = await controller.fetchDefaultWidgetStyle();
// Modify default attributes
// Modify text field attributes
    final textFieldAttr = defaultAttr.textFieldAttr.copyWith(
      fillColor: Colors.lightGreen,
      borderColor: Colors.deepOrange,
      borderWidth: 5,
      fontColor: Colors.black,
      fontSize: 20,
      alignment: CPDFAlignment.center,
      multiline: true,
      familyName: familyName,
      styleName: styleName,
    );

    await controller.updateDefaultWidgetStyle(textFieldAttr);

For more modifiable properties, please refer to the definitions of each form field attribute class, such as CPDFTextFieldAttr, CPDFCheckBoxAttr, etc.