Flatten PDF form fields in C# .NET
Flattening PDF form fields means that you remove form field objects from a document’s internal structure and place their data in the PDF as regular items. This means that form fields are no longer fillable, and their values are no longer available as form field data. The values stay visible as page content.
Download sampleFlattening all form fields
To flatten all form fields in a PDF document, use the FlattenFormFields method:
Register the SDK license before running SDK operations. For setup details, refer to the getting started with .NET SDK guide.
using GdPicture14;
LicenseManager license = new LicenseManager();license.RegisterKEY("");{using GdPicturePDF gdpicturePDF = new GdPicturePDF();gdpicturePDF.LoadFromFile(@"all-pdf-objects.pdf");// Flatten all form fields.gdpicturePDF.FlattenFormFields();gdpicturePDF.SaveToFile(@"output.pdf");}Register the SDK license before running SDK operations. For setup details, refer to the getting started with .NET SDK guide.
Imports GdPicture14
Dim license As LicenseManager = New LicenseManager()license.RegisterKEY("")Using gdpicturePDF As GdPicturePDF = New GdPicturePDF() gdpicturePDF.LoadFromFile("all-pdf-objects.pdf") ' Flatten all form fields. gdpicturePDF.FlattenFormFields() gdpicturePDF.SaveToFile("output.pdf")End UsingFlattening form fields on a specified page
To flatten all form fields on a specific page of a PDF document, use the FlattenFormFields method and specify the page number as its parameter:
{using GdPicturePDF gdpicturePDF = new GdPicturePDF();gdpicturePDF.LoadFromFile(@"all-pdf-objects.pdf");// Flatten form fields on the second page.gdpicturePDF.FlattenFormFields(2);gdpicturePDF.SaveToFile(@"output.pdf");}Using gdpicturePDF As GdPicturePDF = New GdPicturePDF() gdpicturePDF.LoadFromFile("all-pdf-objects.pdf") ' Flatten form fields on the second page. gdpicturePDF.FlattenFormFields(2) gdpicturePDF.SaveToFile("output.pdf")End Using