Articles in this section
Category / Section

How to Flatten the XFA Form Fields in C# and VB.NET?

2 mins read

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, 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.

XFA Form in WinForms PDF

Steps to flatten the XFA form fields programmatically in C#:

  1. Create a new C# console application project. Create a console application in Visual Studio in WinForms PDF
  2. Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET Framework application from NuGet.org. Refer NuGet to the project in WinForms PDF
  3. Include the following namespaces in Program.cs file.

C#

using Syncfusion.Pdf.Xfa;

 

VB.NET

Imports Syncfusion.Pdf.Xfa

 

  1. 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 PDF document.

C#

//Flatten the loaded document 
loadedDocument.Flatten = true;

 

VB.NET

'Flatten the loaded document 
loadedDocument.Flatten = True

 

  1. Include the following code snippet in main method of 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.

Flatten XFA Form in WinForms PDF

The Syncfusion Essential PDF supports creating, filling and flattening the PDF document with 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 form and fill XFA form fields in existing PDF document.

See Also:

Create, fill and flatten PDF form fields

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail 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’s 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 comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied