Guides
预定义表单域
预定义表单域允许您设置默认的表单属性,以便在创建新表单域时自动应用这些属性。您可以通过 CPDFConfiguration 或 CPDFReaderView 来设置预定义表单域属性。
以下是如何设置预定义表单域属性的示例:
通过 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,
}
}
}
})}
/>更多表单域可预定义的属性请参考
CPDFWidgetAttr类的定义。
通过 CPDFReaderView 设置预定义表单域属性
tsx
// 获取当前定义的表单域默认属性
const widgetAttrs = await pdfReaderRef.current?.fetchDefaultWidgetStyle();
// 修改默认属性
// 修改文本域属性
const textFieldAttr: CPDFTextFieldAttr = {
type: "textField",
fillColor: "#FFFF00",
borderColor: "#FF0000",
borderWidth: 2,
};
await pdfReaderRef.current?.updateDefaultWidgetStyle(textFieldAttr);更多可修改的属性请参考各表单域属性类的定义,例如
CPDFTextFieldAttr、CPDFCheckBoxAttr等。