How to Flatten PDF Form Fields in C#

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#

  1. Install Aspose.PDF for .NET NuGet package
  2. Include Aspose.PDF and Aspose.PDF.Facades namespaces
  3. Set Aspose license using License class
  4. Create an instance of Form class
  5. Bind PDF file which you want to flatten
  6. Use FlattenAllField method to merge all form fields
  7. Use FlattenField method to flatten a specific field(s)
  8. 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.