Skip to main content

Removing Form Fields

Version: 12.0

Removing Form Fields

Form fields can be removed individually or all at once. Examples of both are presented below.

Removing an Individual Form Field​

A MergeDocument has a Form property, which has a Fields property. The Fields property is a FormFieldsList that contains the individual form fields. The FormField class has an Output property that accepts a FormFieldOutput enumeration. Remove individual fields by setting the field's FormFieldOutput enumeration's value to FormFieldOutput.Remove. Selecting the Remove option removes the form field.

EnumerationValueDescription
FormFieldOutput.Flatten0The field will be flattened.
FormFieldOutput.Inherit3Field's output will depend on the document's form level output settings.
FormFieldOutput.Remove1The field will be removed.
FormFieldOutput.Retain2The field will be retained.

The following example demonstrates how to remove a form field.

MergeDocument document = new MergeDocument(pdfFilePath);
document.Form.Fields[0].Output = FormFieldOutput.Remove;
document.Draw(pdfFilePath);
Dim MyMergeDocument As MergeDocument = New MergeDocument(pdfFilePath)
MyMergeDocument.Form.Fields(0).Output = FormFieldOutput.Remove
MyMergeDocument.Draw(pdfFilePath)

[FormFieldsRemoveAddExample.cs](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-csharp-examples/Examples/FormFieldsRemoveAddExample.cs){#gitlink-id target=_blank}


[FormFieldsRemoveAddExample.vb](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-vbnet-examples/Examples/FormFieldsRemoveAddExample.vb){#gitlink-id target=_blank}

Removing All Form Fields​

Remove all a form's fields by using the MergeOptions class's FormFields property or by a Form class's Output property.

MergeOptions.FormFields

Use the MergeOptions class to remove all a form's fields by setting the FormFields property to false (the default value is true). The following example omits all form fields.

MergeOptions mergeOptions = new MergeOptions();
mergeOptions.FormFields = false;
MergeDocument document = new MergeDocument(pdfFilePath, mergeOptions );
document.Draw(pdfFilePath);
Dim mergeOptions As MergeOptions = New MergeOptions()
mergeOptions.FormFields = False
Dim document As New MergeDocument(pdfFilePath, mergeOptions)
document.Draw(pdfFilePath)

[FormFieldsRemoveAddExample.cs](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-csharp-examples/Examples/FormFieldsRemoveAddExample.cs){#gitlink-id target=_blank}


[FormFieldsRemoveAddExample.vb](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-vbnet-examples/Examples/FormFieldsRemoveAddExample.vb){#gitlink-id target=_blank}

^^^ form field removing Figure 1. Removing all form fields. ^^^

FormOutput.Remove​

If form fields are not removed by the MergeDocument instance, the fields can still be omitted in the final output of the PDF by using the Form class's Output property (FormOutput enumeration).

FormOutput Fields​

EnumerationValueDescription
FormOutput.Flatten0Form fields will be flattened.
FormOutput.Remove1Form fields will be removed.
FormOutput.Retain2Form fields will be retained.

The following example demonstrates how to remove all form fields using the Output property.

MergeDocument document = new MergeDocument(pdfFilePath);
document.Form.Output = FormOutput.Remove;
document.Draw(pdfFilePath);
Dim MyMergeDocument As MergeDocument = New MergeDocument(pdfFilePath)
MyMergeDocument.Form.Output = FormOutput.Remove
MyMergeDocument.Draw(pdfFilePath)

[FormFieldsRemoveAddExample.cs](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-csharp-examples/Examples/FormFieldsRemoveAddExample.cs){#gitlink-id target=_blank}


[FormFieldsRemoveAddExample.vb](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-vbnet-examples/Examples/FormFieldsRemoveAddExample.vb){#gitlink-id target=_blank}