This sample shows how to flatten form fields in a PDF document.

To flatten form fields in a PDF file please use PdfDocument.FlattenControls() method. This method draws each control on its parent page and then removes the control from the document.

Flattening locks form fields from editing and can significantly reduce output file size.

C#
using System.Diagnostics;

using BitMiracle.Docotic.Pdf;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class FlattenFormFields
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            const string pathToFile = "FlattenFormFields.pdf";

            using (PdfDocument pdf = new PdfDocument("Sample Data/form.pdf"))
            {
                pdf.FlattenControls();

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
    }
}
VB
Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class FlattenFormFields
        Private Sub New()
        End Sub
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.

            Const pathToFile As String = "FlattenFormFields.pdf"

            Using pdf As New PdfDocument("Sample Data\form.pdf")
                pdf.FlattenControls()

                pdf.Save(pathToFile)
            End Using

            Process.Start(pathToFile)
        End Sub
    End Class
End Namespace