We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Clear/Reset all form fields XFA/Acroform using Aspose.PDF for .NET


Is there a method to reset all form fields? (to clear all form fields, no matter if they are xfa or acroforms)

I’ve seen in other libraries the method: object . ResetFormFields (); , but not in Aspose.

Thank you



Thank you for contacting support.

Would you please share sample document and elaborate how would you like to clear the fields. If you want to clear it by clicking a button in PDF document then you can set a JavaScript Action for the button click event, as under:

// Instantiate Document instance
Document pdfDocument = new Document(dataDir + "TestAsposeFeasibility_Output.pdf");

// Iterate through each field
foreach (AsposePdf.Forms.Field formField in pdfDocument.Form.Fields)
    // If the fullname of field contains field_3, perform the operation
    if (formField.FullName.Contains("field_3"))
        // Cast form field as Button
        ButtonField buttonField = (ButtonField)formField;
        // Set JavaScript on an event of the button
        buttonField.OnActivated = new JavascriptAction("this.resetForm([\"field_1\" , \"field_2\"]);");

// Save the updated document
pdfDocument.Save(dataDir + "TestAsposeFeasibility_JS_19.11.pdf");

Where the form contains two fields and one button as an example. Moreover, you may also take a look at FormEditor.ResetFacade method for your kind reference.

Thank you.
The forms are not editable, users are not allowed to change pdf structure, to add or delete fields or buttons, they are supposed to fill the fields only. Adobe Reader/Acrobat do provide a method to Clear Form.
The form reset should be done programmatically, without adding a button or document actions.
In Acrobat library, we can use object.ResetForm(), I was looking for the similar aspose pdf api method. Will check the on you indicated and get back to you.
Thanks again.

The ResetFacade does not work unfortunately.


Kindly share your sample document and SSCCE code that you have tried, so that we may investigate and assist you accordingly.