Resetting Form Fields
RadPdfProcessing supports resetting form fields starting with Q1 2025. The ResetFormAction class represents an action that resets specific form fields in a document. The Fields property contains the list of field names that are included in the reset operation or excluded from it.
The ResetFormType property defines the type of the reset form behavior. The available options are:
| Value | Description |
|---|---|
Include | Specifies that the reset form includes the specified form fields. |
Exclude | Specifies that the reset form excludes the specified form fields. |
Creating a PushButtonWidget with a ResetFormAction
The following example shows how to create a document from scratch, add a form field (for example, CheckBoxField), and a push button that triggers the reset action for the checkbox when you click the button.
RadFixedDocument fixedDocument = new RadFixedDocument();
RadFixedPage fixedPage = fixedDocument.Pages.AddPage();
string fieldName = "SampleCheckBox";
CheckBoxField checkBoxField = new CheckBoxField(fieldName);
checkBoxField.IsChecked = true;
TwoStatesButtonWidget CheckBoxWidget = checkBoxField.Widgets.AddWidget();
CheckBoxWidget.Rect = new Rect(200, 200, 20, 20);
fixedDocument.AcroForm.FormFields.Add(checkBoxField);
fixedDocument.Pages[0].Annotations.Add(CheckBoxWidget);
PushButtonField pushButtonFieldReset = new PushButtonField("SamplePushButton");
PushButtonWidget buttonWidgetReset = pushButtonFieldReset.Widgets.AddWidget();
buttonWidgetReset.Rect = new Rect(0, 0, 250, 50);
buttonWidgetReset.HighlightingMode = HighlightingMode.InvertBorderOfAnnotationRectangle;
ResetFormAction resetFormAction = new ResetFormAction(new List<string>() { fieldName }, ResetFormType.Include);
buttonWidgetReset.Actions.MouseUp.Add(resetFormAction);
buttonWidgetReset.AppearanceCharacteristics.Background = new RgbColor(123, 165, 134);
buttonWidgetReset.AppearanceCharacteristics.NormalCaption = "Reset";
buttonWidgetReset.TextProperties.FontSize = 20;
buttonWidgetReset.TextProperties.Font = FontsRepository.Courier;
buttonWidgetReset.TextProperties.Fill = new RgbColor(0, 0, 0);
buttonWidgetReset.RecalculateContent();
fixedDocument.AcroForm.FormFields.Add(pushButtonFieldReset);
fixedDocument.Pages[0].Annotations.Add(buttonWidgetReset);
In .NET Standard/.NET (Target OS: None) environments, fonts beyond the 14 standard ones require a FontsProvider implementation to be resolved correctly.
Updating an Existing Document with a Field
If the document already contains form fields and a PushButtonWidget, you can access the existing button and add the ResetFormAction.
PushButtonWidget resetPushButtonWidget = ((PushButtonField)fixedDocument.AcroForm.FormFields.Last()).Widgets.First();
ResetFormAction? resetAction = resetPushButtonWidget.Actions.MouseUp.First() as ResetFormAction;
string fieldNameToReset = fixedDocument.AcroForm.FormFields.First().Name;
if (resetAction != null)
{
resetAction.Fields.Add(fieldNameToReset);
resetAction.ResetFormType = ResetFormType.Include;
}