When you want to merge PDF form fields with the content in .NET application, so the fields are not editable, you wonder how to flatten PDF form fields in C# code? Aspose.PDF for .NET API helps answer this question with a few lines of code.
With this .NET API, you can flatten acroform based PDF, all of the form fields at once or select specific fields to flatten in your C# application. The code is same for ASP.NET web application, Windows desktop application, or other .NET platforms.
Follow the below simple and easy steps to programmatically flatten form fields.
Steps to Flatten PDF Form Fields in C#
- Install Aspose.PDF for .NET NuGet package
- Include Aspose.PDF and Aspose.PDF.Facades namespaces
- Set Aspose license using License class
- Create an instance of Form class
- Bind PDF file which you want to flatten
- Use FlattenAllField method to merge all form fields
- Use FlattenField method to flatten a specific field(s)
- Finally, save the flattened output PDF file
Code to Flatten PDF Form Fields in C#
The following C# example uses FlattenField method to merge a particular field with the PDF file. You can flatten as many field as you want with this method by providing the field name as parameter.
Code to Flatten a Single PDF Form Field in C#
Note that, you do not need Adobe Acrobat or any other PDF editing software when flattening PDF form field in C#. This API contains everything you need to programmatically flatten pdf in .NET.