Guides
Predefined Form Fields
The predefined form field feature allows you to set default form properties that will be automatically applied when creating new form fields. You can set predefined form field properties using CPDFConfiguration or CPDFReaderView.
The following examples demonstrate how to set predefined form field properties:
Setting Predefined Form Field Properties via CPDFConfiguration
tsx
<CPDFReaderView
ref={pdfReaderRef}
document={samplePDF}
onViewCreated={onViewCreated}
configuration={ComPDFKit.getDefaultConfig({
formsConfig: {
initAttribute: {
textField: {
type: 'textField',
fillColor: '#FFFF00',
borderColor: '#000000',
borderWidth: 2,
fontSize: 12,
fontColor: '#FFFFFF',
familyName: 'Helvetica',
styleName: 'Bold',
alignment: 'center',
},
checkBox: {
type: 'checkBox',
checkedStyle: CPDFCheckStyle.SQUARE,
checkedColor: '#FF0000',
fillColor: '#00FF00',
borderColor: '#0000FF',
borderWidth: 2,
},
radioButton: {
type: 'radioButton',
checkedStyle: CPDFCheckStyle.CROSS,
checkedColor: '#FF0000',
fillColor: '#00FF00',
borderColor: '#0000FF',
borderWidth: 2,
}
}
}
})}
/>For more predefinable properties of form fields, please refer to the definition of the
CPDFWidgetAttrclass.
Setting Predefined Form Field Properties via CPDFReaderView
tsx
// Get currently defined default form field properties
const widgetAttrs = await pdfReaderRef.current?.fetchDefaultWidgetStyle();
// Modify default properties
// Modify text field properties
const textFieldAttr: CPDFTextFieldAttr = {
type: "textField",
fillColor: "#FFFF00",
borderColor: "#FF0000",
borderWidth: 2,
};
await pdfReaderRef.current?.updateDefaultWidgetStyle(textFieldAttr);For more modifiable properties, please refer to the definitions of each form field attribute class, such as
CPDFTextFieldAttr,CPDFCheckBoxAttr, etc.