How to Flatten the XFA Form Fields in C# and VB.NET?
The Syncfusion Essential PDF is a feature-rich and high-performance .NET PDF library used to create, read, and edit PDF documents programmatically without Adobe dependencies. This library also offers functionality to merge, split, stamp, fill forms, compress, and secure PDF files.
Using this library, you can flatten the XFA form fields in C# and VB.NET. This application uses the following XFA form for flattening.

Steps to flatten the XFA form fields programmatically in C#:
- Create a new C# console application project.

- Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET Framework application from NuGet.org.

- Include the following namespaces in the Program.cs file:
C#
using Syncfusion.Pdf.Xfa;
VB.NET
Imports Syncfusion.Pdf.Xfa
- Flattening the PDF document is nothing but removing the filling and editing capabilities of form fields. Enable the Flatten property of PdfLoadedXfaDocument to flatten the XFA form fields in the PDF document.
C#
// Flatten the loaded document loadedDocument.Flatten = true;
VB.NET
'Flatten the loaded document loadedDocument.Flatten = True
- Include the following code snippet in the main method of the Program.cs file to flatten the XFA form.
C#
// Load the existing XFA document
PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("../../Input/XfaFormTemplate.pdf");
// Flatten the loaded document
loadedDocument.Flatten = true;
// Save the document
loadedDocument.Save("FlattenXFAForm.pdf");
// Close the instance of PdfLoadedXfaDocument
loadedDocument.Close();
// Open the saved file for viewing
System.Diagnostics.Process.Start("FlattenXFAForm.pdf");VB.NET
' Load the existing XFA document
Dim loadedDocument As PdfLoadedXfaDocument = New PdfLoadedXfaDocument("../../Input/XfaFormTemplate.pdf")
' Flatten the loaded document
loadedDocument.Flatten = True;
' Save the document
loadedDocument.Save("FlattenXFAForm.pdf");
' Close the instance of PdfLoadedXfaDocument
loadedDocument.Close();
' Open the saved file for viewing
System.Diagnostics.Process.Start("FlattenXFAForm.pdf") A complete work sample for flattening an XFA form can be downloaded from Flatten-XFA-Form.zip.
By executing the program, you will get the PDF document as follows.

The Syncfusion Essential PDF supports creating, filling, and flattening the PDF document with the following XFA form fields:
- Text box field
- Numeric field
- DateTime field
- Combo box field
- Radio button field
- List box field
- Check box field
- Text Element
- Button
- Line
- Rectangle
- Circle
- Image
Take a moment to peruse the documentation, where you will find other options like creating static and dynamic XFA forms, nested XFA sub-forms, validating XFA form fields, and removing dynamic fields.
Refer here to explore the rich set of Syncfusion® Essential PDF features.
An online sample link to create XFA forms and fill XFA form fields in an existing PDF document.
See Also:
Create, fill, and flatten PDF form fields.
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering a Syncfusion® license key in your application to use the components without a trial message.
Conclusion
I hope you enjoyed learning about how to flatten the XFA form fields in C# and VB.NET.
You can refer to our WinForms PDF feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms Diagram and other WinForms components.
If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!