Deleting Interactive Form
- 3 minutes to read
The PDF Document Processor provides methods that allow you to remove an interactive form field or a whole interactive form from a PDF document.
Removing Form Field
To remove a particular interactive form field by its name:
- Create an instance of the PdfDocumentProcessor class;
- Load a PDF document that contains an interactive form field using one of the PdfDocumentProcessor.LoadDocument overloaded methods;
- If you do not know the name of an interactive form field that should be removed, obtain names of interactive form fields by calling the PdfDocumentProcessor.GetFormFieldNames method;
Remove a desired form field in the interactive form. To do this, call the PdfDocumentProcessor.RemoveFormField method and pass a field name as an argument to this method.
This method tries to find the field in a document using the field name. If it finds this field, the method removes it from the document and returns true; otherwise, it returns false.
See the code snippet below.
using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
// Load a document with an interactive form.
processor.LoadDocument("..\\..\\InteractiveForm.pdf");
// Remove a form field by its name.
if (processor.RemoveFormField("FirstName"))
// Save the modified document.
processor.SaveDocument("..\\..\\Result.pdf");
else
// Shows a message if the form field is not found in a document.
Console.WriteLine("The form field was not removed from a document. Make sure, the form field exists in the document.");
}
Tip
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T494240.
Removing Interactive Form
To remove all form fields from a document:
- Create an instance of the PdfDocumentProcessor class;
- Load a PDF document that contains an interactive form field using one of the PdfDocumentProcessor.LoadDocument overloaded methods;
Call the PdfDocumentProcessor.RemoveForm method.
If the interactive form is successfully removed, this method returns true. If the document does not contain an interactive form that should be removed, it returns false.
See the code snippet below.
using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
// Load a document with an interactive form.
processor.LoadDocument("..\\..\\InteractiveForm.pdf");
// Remove the whole interactive form.
if (processor.RemoveForm())
// Save the modified document.
processor.SaveDocument("..\\..\\Result.pdf");
else
// Shows a message if the interactive form is not found in a document.
Console.WriteLine("The interactive form was not removed from a document. Make sure the interactive form exists in the document.");
}
Tip
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T494240.