VintaSoft Imaging .NET SDK v8.7
In This Topic
    PDF: Working with interactive fields of PDF document
    In This Topic

    Interactive form is a collection of fields for gathering information from user in interactive mode.


    Any field of form is represented by a mandatory field data and optional annotation, which defines the visual appearance of field. The base class that defines the form field data is PdfInteractiveFormField. The base class that defines the annotation, which defines the appearance of from field, is PdfWidgetAnnotation. An instance of PdfInteractiveFormField class stores a link to corresponding instance of PdfWidgetAnnotation class in PdfInteractiveFormField.Annotation property.

    The field may have some child fields, the list of child fields can be obtained using PdfInteractiveFormField.Kids property. The field without child fields is called a terminal field. The terminal field always has the annotation, which defines its appearance. Non-terminal field has no annotation.

    A parent field for the current field can be obtained using PdfInteractiveFormField.Parent property.


    The form field has a partial field name, which is stored in PdfInteractiveFormField.PartialName property and can be set. Also the form field has a full field name, which is stored in PdfInteractiveFormField.FullyQualifiedName property and cannot be set. The full name of form definitely identifies a field in form and is constructed from the partial field name and partial names of parent fields. The partial field name equals the full field name if the field has no parent fields. The parent field name cannot include a dot symbol.


    The SDK supports the following field types:


    A list of form fields, searching a form field

    The list of all form fields can be obtained using PdfDocumentInteractiveForm.Fields property.

    A form field can be found by full field name using PdfDocumentInteractiveForm.FindField method.

    All terminal fields of form can be obtained using PdfDocumentInteractiveForm.GetTerminalFields method. All fields with digital signature can be obtained using PdfDocumentInteractiveForm.GetSignatureFields method.

    Here is an example, that demonstrates how to display the information about all form fields of PDF document:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging.Pdf
    
    ''' <summary>
    ''' Prints information about interactive form of PDF document.
    ''' </summary>
    ''' <param name="pdfFilename">The filename of PDF document.</param>
    Public Shared Sub PrintInformationAboutPdfInteractiveForm(pdfFilename As String)
            ' open PDF document
            Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
                    ' if PDF document has interactive form
                    If document.InteractiveForm IsNot Nothing Then
                            ' get reference to the interactive form
                            Dim form As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm = document.InteractiveForm
    
                            ' get an array that contains all interactive form fields of PDF document
                            Dim formFields As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField() = form.GetTerminalFields()
    
                            ' print information abount field count
                            System.Console.WriteLine("Interactive Form Field Count: {0}", formFields.Length)
    
                            ' for each interactive field
                            For Each field As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField In formFields
                                    ' output information about interactive field
                                    System.Console.WriteLine(vbTab & "Name={0,-18} TypeName={1,-33} TextQuadding={2,-14} IsReadOnly={3,-5}", field.FullyQualifiedName, field.[GetType]().Name, field.TextQuadding, field.IsReadOnly)
                            Next
                    End If
            End Using
    End Sub
    
    ' This code example produces the following output:
    '        Interactive Form Field Count: 13
    '            Name=TextField1         TypeName=PdfInteractiveFormTextField       TextQuadding=Centered       IsReadOnly=False
    '            Name=TextField2         TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
    '            Name=TextField3         TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
    '            Name=TextField4         TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
    '            Name=TextField5         TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
    '            Name=TextField6         TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
    '            Name=NumericField       TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
    '            Name=FileSelect         TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
    '            Name=browseButton       TypeName=PdfInteractiveFormPushButtonField TextQuadding=LeftJustified  IsReadOnly=False
    '            Name=Calculator.Left    TypeName=PdfInteractiveFormTextField       TextQuadding=Centered       IsReadOnly=False
    '            Name=Calculator.Right   TypeName=PdfInteractiveFormTextField       TextQuadding=Centered       IsReadOnly=False
    '            Name=Calculator.Result  TypeName=PdfInteractiveFormTextField       TextQuadding=Centered       IsReadOnly=True
    '            Name=ResetButton        TypeName=PdfInteractiveFormPushButtonField TextQuadding=LeftJustified  IsReadOnly=False
    '
    
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging.Pdf
    
    /// <summary>
    /// Prints information about interactive form of PDF document.
    /// </summary>
    /// <param name="pdfFilename">The filename of PDF document.</param>
    public static void PrintInformationAboutPdfInteractiveForm(string pdfFilename)
    {
        // open PDF document
        using (Vintasoft.Imaging.Pdf.PdfDocument document = 
            new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
        {
            // if PDF document has interactive form
            if (document.InteractiveForm != null)
            {
                // get reference to the interactive form
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm form = document.InteractiveForm;
                
                // get an array that contains all interactive form fields of PDF document
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField[] formFields = form.GetTerminalFields();
                
                // print information abount field count
                System.Console.WriteLine("Interactive Form Field Count: {0}", formFields.Length);
    
                // for each interactive field
                foreach (Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField field in formFields)
                {
                    // output information about interactive field
                    System.Console.WriteLine("\tName={0,-18} TypeName={1,-33} TextQuadding={2,-14} IsReadOnly={3,-5}",
                        field.FullyQualifiedName, field.GetType().Name, field.TextQuadding, field.IsReadOnly);
                }
            }
        }
    }
    
    /* This code example produces the following output:
    Interactive Form Field Count: 13
        Name=TextField1         TypeName=PdfInteractiveFormTextField       TextQuadding=Centered       IsReadOnly=False
        Name=TextField2         TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
        Name=TextField3         TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
        Name=TextField4         TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
        Name=TextField5         TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
        Name=TextField6         TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
        Name=NumericField       TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
        Name=FileSelect         TypeName=PdfInteractiveFormTextField       TextQuadding=LeftJustified  IsReadOnly=False
        Name=browseButton       TypeName=PdfInteractiveFormPushButtonField TextQuadding=LeftJustified  IsReadOnly=False
        Name=Calculator.Left    TypeName=PdfInteractiveFormTextField       TextQuadding=Centered       IsReadOnly=False
        Name=Calculator.Right   TypeName=PdfInteractiveFormTextField       TextQuadding=Centered       IsReadOnly=False
        Name=Calculator.Result  TypeName=PdfInteractiveFormTextField       TextQuadding=Centered       IsReadOnly=True
        Name=ResetButton        TypeName=PdfInteractiveFormPushButtonField TextQuadding=LeftJustified  IsReadOnly=False
    */
                    
    


    Creating a form field

    To add a field to a form is necessary to do the following:

    Here is an example that demonstrates how to create a check box field and add it to a form of PDF document:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Pdf
    
    Class PdfInteractiveFormCheckBoxFieldExample
            ''' <summary>
            ''' Creates a PDF document with the check box fields.
            ''' </summary>
            ''' <param name="filename">The filename.</param>
            Public Shared Sub CreateDocumentWithCheckBoxField(filename As String)
                    ' create PDF document
                    Using document As New Vintasoft.Imaging.Pdf.PdfDocument()
                            ' create interactive form in PDF document
                            document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
    
                            ' specify that the viewer application must construct appearance streams and
                            ' appearance properties for all widget annotations
                            document.InteractiveForm.NeedAppearances = True
    
                            ' create an empty page
                            Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A4)
                            ' add page to the document
                            document.Pages.Add(page)
    
                            Dim fontSize As Single = 20
                            Dim width As Single = fontSize * 3F / 2F
                            Dim height As Single = width
                            ' create a rectangle that defines check box position on PDF page
                            Dim rect As New System.Drawing.RectangleF((page.Size.Width - width) / 2, ((page.Size.Height - height) / 3) * 2, width, height)
    
                            ' create the first check box
                            Dim checkBox1 As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormCheckBoxField(document, "CheckBox1", rect)
                            ' create a rectangle that defines size of the check box content
                            Dim contentRect As New System.Drawing.RectangleF(0, 0, rect.Width, rect.Height)
                            ' get a reference to "ZapfDingbats" font
                            Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.ZapfDingbats)
                            ' create "Yes" appearance of checkbox1
                            Using g As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = checkBox1.CreateYesAppearanceGraphics()
                                    g.DrawString("o", font, fontSize, New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black), contentRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, _
                                            False)
                                    g.DrawString("4", font, fontSize, New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Green), contentRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, _
                                            False)
                            End Using
                            ' create "Off" appearance of checkbox1
                            Using g As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = checkBox1.CreateOffAppearanceGraphics()
                                    g.DrawString("o", font, fontSize, New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black), contentRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, _
                                            False)
                            End Using
                            ' set value of checkbox1
                            checkBox1.Value = "Off"
    
                            ' change the vertical position of rectangle that defines check box position on PDF page
                            rect.Y -= rect.Height
    
                            ' create the second check box
                            Dim checkBox2 As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormCheckBoxField(document, "CheckBox2", rect)
                            ' use checkbox1 appearance as checkbox2 appearance
                            checkBox2.Annotation.Appearances = checkBox1.Annotation.Appearances
                            ' set value of checkBox2
                            checkBox2.Value = "Yes"
    
                            ' add the check box fields to the interactive form of document
                            document.InteractiveForm.Fields.Add(checkBox1)
                            document.InteractiveForm.Fields.Add(checkBox2)
    
                            ' add annotations, associated with check box fields, to the page
                            page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
                            page.Annotations.Add(checkBox1.Annotation)
                            page.Annotations.Add(checkBox2.Annotation)
    
                            ' save the document
                            document.Save(filename)
                    End Using
            End Sub
    End Class
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Pdf
    
    class PdfInteractiveFormCheckBoxFieldExample
    {
        /// <summary>
        /// Creates a PDF document with the check box fields.
        /// </summary>
        /// <param name="filename">The filename.</param>
        public static void CreateDocumentWithCheckBoxField(string filename)
        {
            // create PDF document
            using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument())
            {
                // create interactive form in PDF document
                document.InteractiveForm = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
    
                // specify that the viewer application must construct appearance streams and
                // appearance properties for all widget annotations
                document.InteractiveForm.NeedAppearances = true;
    
                // create an empty page
                Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
                    document, Vintasoft.Imaging.PaperSizeKind.A4);
                // add page to the document
                document.Pages.Add(page);
    
                float fontSize = 20;
                float width = fontSize * 3f / 2f;
                float height = width;
                // create a rectangle that defines check box position on PDF page
                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(
                    (page.Size.Width - width) / 2,
                    ((page.Size.Height - height) / 3) * 2,
                    width, height);
    
                // create the first check box
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormCheckBoxField checkBox1 = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormCheckBoxField(document, "CheckBox1", rect);
                // create a rectangle that defines size of the check box content
                System.Drawing.RectangleF contentRect = new System.Drawing.RectangleF(0, 0, rect.Width, rect.Height);
                // get a reference to "ZapfDingbats" font
                Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = document.FontManager.GetStandardFont(
                    Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.ZapfDingbats);
                // create "Yes" appearance of checkbox1
                using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics g = checkBox1.CreateYesAppearanceGraphics())
                {
                    g.DrawString("o", font, fontSize, new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black), 
                        contentRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, false);
                    g.DrawString("4", font, fontSize, new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Green), 
                        contentRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, false);
                }
                // create "Off" appearance of checkbox1
                using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics g = checkBox1.CreateOffAppearanceGraphics())
                {
                    g.DrawString("o", font, fontSize, new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black), 
                        contentRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, false);
                }
                // set value of checkbox1
                checkBox1.Value = "Off";
    
                // change the vertical position of rectangle that defines check box position on PDF page
                rect.Y -= rect.Height;
    
                // create the second check box
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormCheckBoxField checkBox2 =
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormCheckBoxField(document, "CheckBox2", rect);
                // use checkbox1 appearance as checkbox2 appearance
                checkBox2.Annotation.Appearances = checkBox1.Annotation.Appearances;
                // set value of checkBox2
                checkBox2.Value = "Yes";
    
                // add the check box fields to the interactive form of document
                document.InteractiveForm.Fields.Add(checkBox1);
                document.InteractiveForm.Fields.Add(checkBox2);
    
                // add annotations, associated with check box fields, to the page
                page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
                page.Annotations.Add(checkBox1.Annotation);
                page.Annotations.Add(checkBox2.Annotation);
    
                // save the document
                document.Save(filename);
            }
        }
    }
                    
    


    Here is an example that demonstrates how to create a pushbutton field and add it to a form of PDF document:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Pdf
    
    Class PdfInteractiveFormPushbuttonFieldExample
            ''' <summary>
            ''' Creates a PDF document with push button field.
            ''' </summary>
            ''' <param name="filename">The filename.</param>
            Public Shared Sub CreateDocumentWithPushbuttonField(filename As String)
                    ' create PDF document
                    Using document As New Vintasoft.Imaging.Pdf.PdfDocument()
                            ' create interactive form in PDF document
                            document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
    
                            ' specify that the viewer application must construct appearance streams and
                            ' appearance properties for all widget annotations
                            document.InteractiveForm.NeedAppearances = True
    
                            ' create an empty page
                            Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A4)
                            ' add page to the document
                            document.Pages.Add(page)
    
                            Dim width As Single = 70
                            Dim height As Single = 30
                            ' create a rectangle that defines push box position on PDF page
                            Dim rect As New System.Drawing.RectangleF((page.Size.Width - width) / 2, ((page.Size.Height - height) / 3) * 2, width, height)
    
                            ' create a push button field
                            Dim button As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField(document, "BestFitButton", rect)
    
                            ' set the border style
                            button.Annotation.BorderStyle = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document)
                            button.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled
                            button.Annotation.BorderStyle.Width = 1
    
                            ' set the appearance characteristics
                            button.Annotation.AppearanceCharacteristics = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document)
                            button.Annotation.AppearanceCharacteristics.BackgroundColor = System.Drawing.Color.LightGray
                            button.Annotation.AppearanceCharacteristics.ButtonNormalCaption = "BestFit"
    
                            ' set the activate action
                            button.Annotation.ActivateAction = New Vintasoft.Imaging.Pdf.Tree.PdfGotoAction(New Vintasoft.Imaging.Pdf.Tree.PdfDestinationFit(document, page))
    
                            ' set the default appearance of text
                            Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
                            button.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black)
    
                            ' add the push button field to the interactive form of document
                            document.InteractiveForm.Fields.Add(button)
    
                            ' add annotation, associated with push button field, to the page
                            page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
                            page.Annotations.Add(button.Annotation)
    
                            ' save the document
                            document.Save(filename)
                    End Using
            End Sub
    End Class
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Pdf
    
    class PdfInteractiveFormPushbuttonFieldExample
    {
        /// <summary>
        /// Creates a PDF document with push button field.
        /// </summary>
        /// <param name="filename">The filename.</param>
        public static void CreateDocumentWithPushbuttonField(string filename)
        {
            // create PDF document
            using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument())
            {
                // create interactive form in PDF document
                document.InteractiveForm = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
    
                // specify that the viewer application must construct appearance streams and
                // appearance properties for all widget annotations
                document.InteractiveForm.NeedAppearances = true;
    
                // create an empty page
                Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
                    document, Vintasoft.Imaging.PaperSizeKind.A4);
                // add page to the document
                document.Pages.Add(page);
    
                float width = 70;
                float height = 30;
                // create a rectangle that defines push box position on PDF page
                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(
                    (page.Size.Width - width) / 2,
                    ((page.Size.Height - height) / 3) * 2,
                    width, height);
    
                // create a push button field
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField button = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField(
                        document, "BestFitButton", rect);
                
                // set the border style
                button.Annotation.BorderStyle = 
                    new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document);
                button.Annotation.BorderStyle.Style = 
                    Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled;
                button.Annotation.BorderStyle.Width = 1;
                
                // set the appearance characteristics
                button.Annotation.AppearanceCharacteristics = 
                    new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document);
                button.Annotation.AppearanceCharacteristics.BackgroundColor = System.Drawing.Color.LightGray;
                button.Annotation.AppearanceCharacteristics.ButtonNormalCaption = "BestFit";
                
                // set the activate action
                button.Annotation.ActivateAction = new Vintasoft.Imaging.Pdf.Tree.PdfGotoAction(
                    new Vintasoft.Imaging.Pdf.Tree.PdfDestinationFit(document, page));
                
                // set the default appearance of text
                Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = document.FontManager.GetStandardFont(
                    Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
                button.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black);
    
                // add the push button field to the interactive form of document
                document.InteractiveForm.Fields.Add(button);
    
                // add annotation, associated with push button field, to the page
                page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
                page.Annotations.Add(button.Annotation);
                
                // save the document
                document.Save(filename);
            }
        }
    }
                    
    


    Here is an example that demonstrates how to create a group of radio buttons and add it to a form of PDF document:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Pdf
    
    Class PdfInteractiveFormRadioButtonGroupFieldExample
            ''' <summary>
            ''' Creates a PDF document with radio button group fields.
            ''' </summary>
            ''' <param name="filename">The filename.</param>
            Public Shared Sub CreateDocumentWithRadioButtonGroupField(filename As String)
                    ' create PDF document
                    Using document As New Vintasoft.Imaging.Pdf.PdfDocument()
                            ' create interactive form in PDF document
                            document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
    
                            ' specify that the viewer application must construct appearance streams and
                            ' appearance properties for all widget annotations
                            document.InteractiveForm.NeedAppearances = True
    
                            ' create an empty page
                            Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A4)
                            ' add page to the document
                            document.Pages.Add(page)
    
                            ' "ZapfDingbats" font
                            Dim fontSize As Single = 15
                            Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.ZapfDingbats)
    
                            Dim width As Single = 100
                            Dim height As Single = 30
                            ' create a rectangle that defines the first radio button group position on PDF page
                            Dim rect As New System.Drawing.RectangleF((page.Size.Width - width) / 2, ((page.Size.Height - height) / 3) * 2, width, height)
    
                            ' create the first radio button group
                            Dim radioGroup1 As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormRadioButtonGroupField(document, "RadioGroup1")
                            ' add radio buttons to the radio button group
                            AddSimpleRadioButtons(radioGroup1, font, fontSize, rect, System.Drawing.Color.Green, "1", _
                                    "2", "3", "4", "5")
                            ' change the state of radio button with value "2" to the checked state
                            radioGroup1.CheckedAppearanceStateName = "2"
    
                            ' create a rectangle that defines the second radio button group position on PDF page
                            rect = New System.Drawing.RectangleF(rect.X, rect.Y - rect.Height, rect.Width, rect.Height)
    
                            ' create the second radio button group
                            Dim radioGroup2 As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormRadioButtonGroupField(document, "RadioGroup2")
                            ' add radio buttons to the radio button group
                            AddSimpleRadioButtons(radioGroup2, font, fontSize, rect, System.Drawing.Color.Red, "One", _
                                    "Two", "Three")
                            ' change the state of radio button with value "Two" to the checked state
                            radioGroup2.CheckedAppearanceStateName = "Two"
    
                            ' add radio button groups to the interactive form of document
                            document.InteractiveForm.Fields.Add(radioGroup1)
                            document.InteractiveForm.Fields.Add(radioGroup2)
    
                            ' add annotations, associated with radio button group fields, to the page
                            page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
                            page.Annotations.AddRange(radioGroup1.GetAnnotations())
                            page.Annotations.AddRange(radioGroup2.GetAnnotations())
    
                            ' save the document
                            document.Save(filename)
                    End Using
            End Sub
    
            ''' <summary>
            ''' Adds simple radio buttons to a radio button group.
            ''' </summary>
            ''' <param name="radioButtonGroup">The parent radio button group.</param>
            ''' <param name="font">The font.</param>
            ''' <param name="fontSize">The font size.</param>
            ''' <param name="rect">Rectangle that defines radio button group position on PDF page.</param>
            ''' <param name="onColor">Button color in "on" state.</param>
            ''' <param name="values">The values of radio buttons.</param>
            Private Shared Sub AddSimpleRadioButtons(radioButtonGroup As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormRadioButtonGroupField, font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont, fontSize As Single, rect As System.Drawing.RectangleF, onColor As System.Drawing.Color, ParamArray values As String())
                    Dim offBrush As New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black)
                    Dim onBrush As New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(onColor)
    
                    ' for each value
                    For i As Integer = 0 To values.Length - 1
                            ' create a rectangle that defines radio button position on PDF page
                            Dim radioButtonRect As New System.Drawing.RectangleF(rect.X + i * rect.Width / values.Length, rect.Y, rect.Width / values.Length, rect.Height)
    
                            ' create a radio button
                            Dim radioButton As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormRadioButtonField(radioButtonGroup.Document, radioButtonRect)
    
                            ' create a rectangle that defines size of the radio button content
                            radioButtonRect = New System.Drawing.RectangleF(0, 0, radioButtonRect.Width, radioButtonRect.Height)
    
                            ' create ON button appearance
                            Using g As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = radioButton.CreateAppearanceGraphics(values(i))
                                    g.DrawString("m", font, fontSize, offBrush, radioButtonRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, _
                                            False)
                                    g.DrawString("l", font, fontSize, onBrush, radioButtonRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, _
                                            False)
                            End Using
                            ' create "Off" button appearance
                            Using g As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = radioButton.CreateOffAppearanceGraphics()
                                    g.DrawString("m", font, fontSize, offBrush, radioButtonRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, _
                                            False)
                            End Using
    
                            ' add new radio button to radio button group
                            radioButtonGroup.Kids.Add(radioButton)
                    Next
            End Sub
    End Class
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Pdf
    
    class PdfInteractiveFormRadioButtonGroupFieldExample
    {
        /// <summary>
        /// Creates a PDF document with radio button group fields.
        /// </summary>
        /// <param name="filename">The filename.</param>
        public static void CreateDocumentWithRadioButtonGroupField(string filename)
        {
            // create PDF document
            using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument())
            {
                // create interactive form in PDF document
                document.InteractiveForm = new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
    
                // specify that the viewer application must construct appearance streams and
                // appearance properties for all widget annotations
                document.InteractiveForm.NeedAppearances = true;
    
                // create an empty page
                Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
                    document, Vintasoft.Imaging.PaperSizeKind.A4);
                // add page to the document
                document.Pages.Add(page);
    
                // "ZapfDingbats" font
                float fontSize = 15;
                Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = document.FontManager.GetStandardFont(
                    Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.ZapfDingbats);
    
                float width = 100;
                float height = 30;
                // create a rectangle that defines the first radio button group position on PDF page
                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(
                    (page.Size.Width - width) / 2,
                    ((page.Size.Height - height) / 3) * 2,
                    width, height);
    
                // create the first radio button group
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormRadioButtonGroupField radioGroup1 = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormRadioButtonGroupField(document, "RadioGroup1");
                // add radio buttons to the radio button group
                AddSimpleRadioButtons(radioGroup1, font, fontSize, rect, System.Drawing.Color.Green, "1", "2", "3", "4", "5");
                // change the state of radio button with value "2" to the checked state
                radioGroup1.CheckedAppearanceStateName = "2";
    
                // create a rectangle that defines the second radio button group position on PDF page
                rect = new System.Drawing.RectangleF(rect.X, rect.Y - rect.Height, rect.Width, rect.Height);
    
                // create the second radio button group
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormRadioButtonGroupField radioGroup2 =
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormRadioButtonGroupField(document, "RadioGroup2");
                // add radio buttons to the radio button group
                AddSimpleRadioButtons(radioGroup2, font, fontSize, rect, System.Drawing.Color.Red, "One", "Two", "Three");
                // change the state of radio button with value "Two" to the checked state
                radioGroup2.CheckedAppearanceStateName = "Two";
    
                // add radio button groups to the interactive form of document
                document.InteractiveForm.Fields.Add(radioGroup1);
                document.InteractiveForm.Fields.Add(radioGroup2);
    
                // add annotations, associated with radio button group fields, to the page
                page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
                page.Annotations.AddRange(radioGroup1.GetAnnotations());
                page.Annotations.AddRange(radioGroup2.GetAnnotations());
    
                // save the document
                document.Save(filename);
            }
        }
    
        /// <summary>
        /// Adds simple radio buttons to a radio button group.
        /// </summary>
        /// <param name="radioButtonGroup">The parent radio button group.</param>
        /// <param name="font">The font.</param>
        /// <param name="fontSize">The font size.</param>
        /// <param name="rect">Rectangle that defines radio button group position on PDF page.</param>
        /// <param name="onColor">Button color in "on" state.</param>
        /// <param name="values">The values of radio buttons.</param>
        private static void AddSimpleRadioButtons(
            Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormRadioButtonGroupField radioButtonGroup,
            Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font,
            float fontSize, 
            System.Drawing.RectangleF rect,
            System.Drawing.Color onColor,
            params string[] values)
        {
            Vintasoft.Imaging.Pdf.Drawing.PdfBrush offBrush = 
                new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black);
            Vintasoft.Imaging.Pdf.Drawing.PdfBrush onBrush = 
                new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(onColor);
    
            // for each value
            for (int i = 0; i < values.Length; i++)
            {
                // create a rectangle that defines radio button position on PDF page
                System.Drawing.RectangleF radioButtonRect = new System.Drawing.RectangleF(
                    rect.X + i * rect.Width / values.Length, rect.Y, rect.Width / values.Length, rect.Height);
                
                // create a radio button
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormRadioButtonField radioButton = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormRadioButtonField(
                        radioButtonGroup.Document, radioButtonRect);
    
                // create a rectangle that defines size of the radio button content
                radioButtonRect = new System.Drawing.RectangleF(0, 0, radioButtonRect.Width, radioButtonRect.Height);
                
                // create ON button appearance
                using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics g = radioButton.CreateAppearanceGraphics(values[i]))
                {
                    g.DrawString("m", font, fontSize, offBrush, radioButtonRect, 
                        Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, false);
                    g.DrawString("l", font, fontSize, onBrush, radioButtonRect, 
                        Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, false);
                }
                // create "Off" button appearance
                using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics g = radioButton.CreateOffAppearanceGraphics())
                {
                    g.DrawString("m", font, fontSize, offBrush, radioButtonRect, 
                        Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, false);
                }
    
                // add new radio button to radio button group
                radioButtonGroup.Kids.Add(radioButton);
            }
        }
    }
                    
    


    Here is an example that demonstrates how to create a combo box field and add it to a form of PDF document:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Pdf
    
    Class PdfInteractiveFormComboBoxFieldExample
            ''' <summary>
            ''' Creates a PDF document with the combo box fields.
            ''' </summary>
            ''' <param name="filename">The filename.</param>
            Public Shared Sub CreateDocumentWithComboBoxField(filename As String)
                    ' create PDF document
                    Using document As New Vintasoft.Imaging.Pdf.PdfDocument()
                            ' create interactive form in PDF document
                            document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
    
                            ' specify that the viewer application must construct appearance streams and
                            ' appearance properties for all widget annotations
                            document.InteractiveForm.NeedAppearances = True
    
                            ' create an empty page
                            Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A4)
                            ' add page to the document
                            document.Pages.Add(page)
    
                            Dim width As Single = 70
                            Dim height As Single = 20
                            ' create a rectangle that defines check box position on PDF page
                            Dim rect As New System.Drawing.RectangleF((page.Size.Width - width) / 2, ((page.Size.Height - height) / 3) * 2, width, height)
    
                            ' create a combo box field
                            Dim comboBox As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormComboBoxField(document, "ComboBox1", rect, New String() {"Item1", "Item2", "Item3"})
                            ' set the selected item
                            comboBox.SelectedItem = "Item2"
                            ' set the defaul selected item
                            comboBox.DefaultSelectedItem = comboBox.SelectedItem
    
                            ' set the border style
                            comboBox.Annotation.BorderStyle = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document)
                            comboBox.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled
                            comboBox.Annotation.BorderStyle.Width = 1
    
                            ' set the appearance characteristics
                            comboBox.Annotation.AppearanceCharacteristics = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document)
                            comboBox.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray
    
                            ' sets the default appearance of text
                            Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
                            comboBox.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black)
    
                            ' add combo box field to the interactive form of document
                            document.InteractiveForm.Fields.Add(comboBox)
    
                            ' add annotation, associated with combobox field, to the page
                            page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
                            page.Annotations.Add(comboBox.Annotation)
    
                            ' save the document
                            document.Save(filename)
                    End Using
            End Sub
    End Class
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Pdf
    
    class PdfInteractiveFormComboBoxFieldExample
    {
        /// <summary>
        /// Creates a PDF document with the combo box fields.
        /// </summary>
        /// <param name="filename">The filename.</param>
        public static void CreateDocumentWithComboBoxField(string filename)
        {
            // create PDF document
            using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument())
            {
                // create interactive form in PDF document
                document.InteractiveForm = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
    
                // specify that the viewer application must construct appearance streams and
                // appearance properties for all widget annotations
                document.InteractiveForm.NeedAppearances = true;
    
                // create an empty page
                Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
                    document, Vintasoft.Imaging.PaperSizeKind.A4);
                // add page to the document
                document.Pages.Add(page);
    
                float width = 70;
                float height = 20;
                // create a rectangle that defines check box position on PDF page
                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(
                    (page.Size.Width - width) / 2,
                    ((page.Size.Height - height) / 3) * 2,
                    width, height);
    
                // create a combo box field
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormComboBoxField comboBox = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormComboBoxField(
                        document, "ComboBox1", rect, new string[] { "Item1", "Item2", "Item3" });
                // set the selected item
                comboBox.SelectedItem = "Item2";
                // set the defaul selected item
                comboBox.DefaultSelectedItem = comboBox.SelectedItem;
                
                // set the border style
                comboBox.Annotation.BorderStyle = 
                    new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document);
                comboBox.Annotation.BorderStyle.Style = 
                    Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled;
                comboBox.Annotation.BorderStyle.Width = 1;
                
                // set the appearance characteristics
                comboBox.Annotation.AppearanceCharacteristics = 
                    new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document);
                comboBox.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray;
                
                // sets the default appearance of text
                Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = document.FontManager.GetStandardFont(
                    Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
                comboBox.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black);
    
                // add combo box field to the interactive form of document
                document.InteractiveForm.Fields.Add(comboBox);
    
                // add annotation, associated with combobox field, to the page
                page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
                page.Annotations.Add(comboBox.Annotation);
    
                // save the document
                document.Save(filename);
            }
        }
    }
                    
    


    Here is an example that demonstrates how to create a list box field and add it to a form of PDF document:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Pdf
    
    Class PdfInteractiveFormListBoxFieldExample
            ''' <summary>
            ''' Creates a PDF document with the list box field.
            ''' </summary>
            ''' <param name="filename">The filename.</param>
            Public Shared Sub CreateDocumentWithListBoxField(filename As String)
                    ' create PDF document
                    Using document As New Vintasoft.Imaging.Pdf.PdfDocument()
                            ' create interactive form in PDF document
                            document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
    
                            ' specify that the viewer application must construct appearance streams and
                            ' appearance properties for all widget annotations
                            document.InteractiveForm.NeedAppearances = True
    
                            ' create an empty page
                            Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A4)
                            ' add page to the document
                            document.Pages.Add(page)
    
                            Dim width As Single = 60
                            Dim height As Single = 70
                            ' create a rectangle that defines list box position on PDF page
                            Dim rect As New System.Drawing.RectangleF((page.Size.Width - width) / 2, ((page.Size.Height - height) / 3) * 2, width, height)
    
                            ' create a list box field
                            Dim listBox As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormListBoxField(document, "ListBox1", rect, New String() {"Item1", "Item2", "Item3"})
                            ' set the selected item
                            listBox.SelectedItem = "Item2"
                            ' set yje default selected item
                            listBox.DefaultSelectedItem = listBox.SelectedItem
    
                            ' set the border style
                            listBox.Annotation.BorderStyle = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document)
                            listBox.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled
                            listBox.Annotation.BorderStyle.Width = 1
    
                            ' set the appearance characteristics
                            listBox.Annotation.AppearanceCharacteristics = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document)
                            listBox.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray
    
                            ' set the default appearance of text
                            Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
                            listBox.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black)
    
                            ' add the list box field to the interactive form of document
                            document.InteractiveForm.Fields.Add(listBox)
    
                            ' add annotation, associated with list box field, to the page
                            page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
                            page.Annotations.Add(listBox.Annotation)
    
                            ' save the document
                            document.Save(filename)
                    End Using
            End Sub
    End Class
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Pdf
    
    class PdfInteractiveFormListBoxFieldExample
    {
        /// <summary>
        /// Creates a PDF document with the list box field.
        /// </summary>
        /// <param name="filename">The filename.</param>
        public static void CreateDocumentWithListBoxField(string filename)
        {
            // create PDF document
            using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument())
            {
                // create interactive form in PDF document
                document.InteractiveForm = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
    
                // specify that the viewer application must construct appearance streams and
                // appearance properties for all widget annotations
                document.InteractiveForm.NeedAppearances = true;
    
                // create an empty page
                Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
                    document, Vintasoft.Imaging.PaperSizeKind.A4);
                // add page to the document
                document.Pages.Add(page);
    
                float width = 60;
                float height = 70;
                // create a rectangle that defines list box position on PDF page
                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(
                    (page.Size.Width - width) / 2,
                    ((page.Size.Height - height) / 3) * 2,
                    width, height);
    
                // create a list box field
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormListBoxField listBox = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormListBoxField(
                        document, "ListBox1", rect, new string[] { "Item1", "Item2", "Item3" });
                // set the selected item
                listBox.SelectedItem = "Item2";
                // set yje default selected item
                listBox.DefaultSelectedItem = listBox.SelectedItem;
                
                // set the border style
                listBox.Annotation.BorderStyle = 
                    new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document);
                listBox.Annotation.BorderStyle.Style = 
                    Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled;
                listBox.Annotation.BorderStyle.Width = 1;
                
                // set the appearance characteristics
                listBox.Annotation.AppearanceCharacteristics = 
                    new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document);
                listBox.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray;
    
                // set the default appearance of text
                Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = document.FontManager.GetStandardFont(
                    Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
                listBox.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black);
    
                // add the list box field to the interactive form of document
                document.InteractiveForm.Fields.Add(listBox);
    
                // add annotation, associated with list box field, to the page
                page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
                page.Annotations.Add(listBox.Annotation);
    
                // save the document
                document.Save(filename);
            }
        }
    }
                    
    


    Here is an example that demonstrates how to create a text input field and add it to a form of PDF document:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Pdf
    
    Class PdfInteractiveFormTextFieldExample
            ''' <summary>
            ''' Creates a PDF document with numeric text field.
            ''' </summary>
            ''' <param name="filename">The filename.</param>
            Public Shared Sub CreateDocumentWithNumericTextField(filename As String)
                    ' create PDF document
                    Using document As New Vintasoft.Imaging.Pdf.PdfDocument()
                            ' create interactive form in PDF document
                            document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
    
                            ' specify that the viewer application must construct appearance streams and
                            ' appearance properties for all widget annotations
                            document.InteractiveForm.NeedAppearances = True
    
                            ' create an empty page
                            Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A4)
                            ' add page to the document
                            document.Pages.Add(page)
    
                            Dim width As Single = 100
                            Dim height As Single = 25
                            ' create a rectangle that defines the field position on PDF page
                            Dim rect As New System.Drawing.RectangleF((page.Size.Width - width) / 2, ((page.Size.Height - height) / 3) * 2, width, height)
    
                            ' create a text field
                            Dim textField As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField(document, "NumericField", rect, "12345")
    
                            ' create the text value validation method that accepts numbers (0-9 digits) only
                            Dim javaScriptCode As String = "var regex = /[^0-9]/;if(regex.test(event.change)) event.change = '';"
                            Dim action As New Vintasoft.Imaging.Pdf.Tree.PdfJavaScriptAction(document, javaScriptCode)
                            textField.AdditionalActions = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldAdditionalActions(document)
                            ' set the validation action for the AdditionalActions.Keystroke trigger event
                            textField.AdditionalActions.Keystroke = action
    
                            ' set the default appearance of text
                            Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
                            textField.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black)
    
                            ' set the border style
                            textField.Annotation.BorderStyle = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document)
                            textField.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Inset
                            textField.Annotation.BorderStyle.Width = 1
    
                            ' set the appearance characteristics
                            textField.Annotation.AppearanceCharacteristics = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document)
                            textField.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray
    
                            ' add the text field to the interactive form of document
                            document.InteractiveForm.Fields.Add(textField)
    
                            ' add annotation, associated with the text field, to the page
                            page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
                            page.Annotations.Add(textField.Annotation)
    
                            ' save the document
                            document.Save(filename)
                    End Using
            End Sub
    End Class
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Pdf
    
    class PdfInteractiveFormTextFieldExample
    {
        /// <summary>
        /// Creates a PDF document with numeric text field.
        /// </summary>
        /// <param name="filename">The filename.</param>
        public static void CreateDocumentWithNumericTextField(string filename)
        {
            // create PDF document
            using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument())
            {
                // create interactive form in PDF document
                document.InteractiveForm = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
    
                // specify that the viewer application must construct appearance streams and
                // appearance properties for all widget annotations
                document.InteractiveForm.NeedAppearances = true;
    
                // create an empty page
                Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
                    document, Vintasoft.Imaging.PaperSizeKind.A4);
                // add page to the document
                document.Pages.Add(page);
    
                float width = 100;
                float height = 25;
                // create a rectangle that defines the field position on PDF page
                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(
                    (page.Size.Width - width) / 2,
                    ((page.Size.Height - height) / 3) * 2,
                    width, height);
    
                // create a text field
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField textField =
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField(
                        document, "NumericField", rect, "12345");
    
                // create the text value validation method that accepts numbers (0-9 digits) only
                string javaScriptCode = 
                    "var regex = /[^0-9]/;if(regex.test(event.change)) event.change = '';";
                Vintasoft.Imaging.Pdf.Tree.PdfJavaScriptAction action = 
                    new Vintasoft.Imaging.Pdf.Tree.PdfJavaScriptAction(document, javaScriptCode);
                textField.AdditionalActions = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldAdditionalActions(document);
                // set the validation action for the AdditionalActions.Keystroke trigger event
                textField.AdditionalActions.Keystroke = action;
    
                // set the default appearance of text
                Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = document.FontManager.GetStandardFont(
                    Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
                textField.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black);
    
                // set the border style
                textField.Annotation.BorderStyle = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document);
                textField.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Inset;
                textField.Annotation.BorderStyle.Width = 1;
                
                // set the appearance characteristics
                textField.Annotation.AppearanceCharacteristics = 
                    new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document);
                textField.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray;
    
                // add the text field to the interactive form of document
                document.InteractiveForm.Fields.Add(textField);
    
                // add annotation, associated with the text field, to the page
                page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
                page.Annotations.Add(textField.Annotation);
    
                // save the document
                document.Save(filename);
            }
        }
    }
                    
    


    Here is an example that demonstrates how to create a barcode field and add it to a form of PDF document:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Pdf
    
    Class PdfInteractiveFormBarcodeFieldExample
            ''' <summary>
            ''' Creates a PDF document with barcode field.
            ''' </summary>
            ''' <param name="filename">The filename.</param>
            ''' <param name="barcodeSymbology">The barcode symbology.</param>
            Public Shared Sub CreateDocumentWithBarcodeField(filename As String, barcodeSymbology As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.BarcodeSymbologyType)
                    ' create PDF document
                    Using document As New Vintasoft.Imaging.Pdf.PdfDocument(New Vintasoft.Imaging.Pdf.PdfFormat("1.7", False, True))
                            ' create interactive form in PDF document
                            document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
                            document.InteractiveForm.CalculationOrder = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldList(document)
    
                            ' create an empty page
                            Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A4)
                            page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
                            ' add page to the document
                            document.Pages.Add(page)
    
    
                            Dim width As Single = 200
                            Dim height As Single = 25
                            ' create a rectangle that defines the field position on PDF page
                            Dim rect As New System.Drawing.RectangleF((page.Size.Width - width) / 2, page.Size.Height - height * 8, width, height)
    
                            ' create text field (barcode value)
                            Dim textField As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField(document, "TextField", rect)
                            textField.TextValue = "test"
                            textField.DefaultValue = textField.Value
                            ' set the text default appearance
                            textField.SetTextDefaultAppearance(document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman), 12, System.Drawing.Color.Black)
                            ' set the appearance characteristics
                            textField.Annotation.AppearanceCharacteristics = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document)
                            textField.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray
                            textField.Annotation.BorderStyle = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document)
                            textField.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled
                            document.InteractiveForm.AddField(textField, page)
    
    
                            width = 200
                            height = 150
                            ' create a rectangle that defines the field position on PDF page
                            rect = New System.Drawing.RectangleF((page.Size.Width - width) / 2, ((page.Size.Height - height) / 3) * 2, width, height)
    
                            ' create a barcode field
                            Dim barcodeField As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormBarcodeField(document, "BarcodeField", barcodeSymbology, rect)
    
                            ' set barcode field value
                            barcodeField.TextValue = textField.TextValue
    
                            ' set the barcode single module width to 0.02 inch
                            barcodeField.ModuleWidth = 0.02F
    
                            ' add the text field to the interactive form of document
                            document.InteractiveForm.Fields.Add(barcodeField)
    
                            ' add annotation, associated with the text field, to the page
                            page.Annotations.Add(barcodeField.Annotation)
    
                            ' create the calculate action of barcode value
                            Dim calculateValueAction As New Vintasoft.Imaging.Pdf.Tree.PdfJavaScriptAction(document, "event.value = this.getField('TextField').value;")
    
                            ' add the barcode field to the calculated fields (calcualtion order)
                            ' of the document interactive form fields
                            barcodeField.AdditionalActions = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldAdditionalActions(document)
                            barcodeField.AdditionalActions.Calculate = calculateValueAction
                            document.InteractiveForm.CalculationOrder.Add(barcodeField)
    
                            ' update (create) field appearances
                            document.InteractiveForm.UpdateAppearances()
    
                            ' save the document
                            document.Save(filename)
                    End Using
            End Sub
    End Class
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Pdf
    
    class PdfInteractiveFormBarcodeFieldExample
    {
        /// <summary>
        /// Creates a PDF document with barcode field.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <param name="barcodeSymbology">The barcode symbology.</param>
        public static void CreateDocumentWithBarcodeField(string filename,
            Vintasoft.Imaging.Pdf.Tree.InteractiveForms.BarcodeSymbologyType barcodeSymbology)
        {
            // create PDF document
            using (Vintasoft.Imaging.Pdf.PdfDocument document = 
                new Vintasoft.Imaging.Pdf.PdfDocument(
                    new Vintasoft.Imaging.Pdf.PdfFormat("1.7", false, true)))
            {
                // create interactive form in PDF document
                document.InteractiveForm = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
                document.InteractiveForm.CalculationOrder =
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldList(document);
    
                // create an empty page
                Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
                    document, Vintasoft.Imaging.PaperSizeKind.A4);
                page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
                // add page to the document
                document.Pages.Add(page);
    
    
                float width = 200;
                float height = 25;
                // create a rectangle that defines the field position on PDF page
                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(
                    (page.Size.Width - width) / 2,
                    page.Size.Height - height * 8,
                    width, height);
    
                // create text field (barcode value)
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField textField = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField(
                        document, "TextField", rect);
                textField.TextValue = "test";
                textField.DefaultValue = textField.Value;
                // set the text default appearance
                textField.SetTextDefaultAppearance(
                    document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman), 
                    12, System.Drawing.Color.Black);
                // set the appearance characteristics
                textField.Annotation.AppearanceCharacteristics =
                    new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document);
                textField.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray;
                textField.Annotation.BorderStyle = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document);
                textField.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled;
                document.InteractiveForm.AddField(textField, page);
    
    
                width = 200;
                height = 150;
                // create a rectangle that defines the field position on PDF page
                rect = new System.Drawing.RectangleF(
                    (page.Size.Width - width) / 2,
                    ((page.Size.Height - height) / 3) * 2,
                    width, height);
    
                // create a barcode field
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormBarcodeField barcodeField = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormBarcodeField(
                        document, "BarcodeField", barcodeSymbology, rect);
    
                // set barcode field value
                barcodeField.TextValue = textField.TextValue;
    
                // set the barcode single module width to 0.02 inch
                barcodeField.ModuleWidth = 0.02f;
    
                // add the text field to the interactive form of document
                document.InteractiveForm.Fields.Add(barcodeField);
    
                // add annotation, associated with the text field, to the page
                page.Annotations.Add(barcodeField.Annotation);
    
                // create the calculate action of barcode value
                Vintasoft.Imaging.Pdf.Tree.PdfJavaScriptAction calculateValueAction = 
                    new Vintasoft.Imaging.Pdf.Tree.PdfJavaScriptAction(document,
                        @"event.value = this.getField('TextField').value;");
    
                // add the barcode field to the calculated fields (calcualtion order)
                // of the document interactive form fields
                barcodeField.AdditionalActions = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldAdditionalActions(document);
                barcodeField.AdditionalActions.Calculate = calculateValueAction;
                document.InteractiveForm.CalculationOrder.Add(barcodeField);
    
                // update (create) field appearances
                document.InteractiveForm.UpdateAppearances();
    
                // save the document
                document.Save(filename);
            }
        }
    }
                    
    


    Here is an example that demonstrates how to create a signature field and add it to a form of PDF document, i.e. to sign the document via digital signature for authenticating the user identity and the validity of content:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Pdf
    
    ''' <summary>
    ''' Signs a PDF or PDF/A document using specified certificate.
    ''' </summary>
    ''' <param name="inputFilename">The filename of input PDF document.</param>
    ''' <param name="outputFilename">The filename of output PDF document.</param>
    ''' <param name="certificate">The certificate that should be used
    ''' for signing the input PDF document.</param>
    Public Shared Sub SignDocument(inputFilename As String, outputFilename As String, certificate As System.Security.Cryptography.X509Certificates.X509Certificate2, conformance As Vintasoft.Imaging.Pdf.PdfDocumentConformance)
            Dim converter As Vintasoft.Imaging.Pdf.Processing.PdfDocumentConverter = Nothing
            ' if PDF document conformance is specified
            If conformance <> Vintasoft.Imaging.Pdf.PdfDocumentConformance.Undefined Then
                    ' create PDF document converter
                    converter = Vintasoft.Imaging.Pdf.Processing.PdfDocumentConverter.Create(conformance)
                    ' if PDF document converter is not found
                    If converter Is Nothing Then
                            Dim message As String = String.Format("Unsupported {0} conformance.", conformance)
                            Throw New System.ArgumentOutOfRangeException(message)
                    End If
            End If
    
            ' open PDF document
            Using document As New Vintasoft.Imaging.Pdf.PdfDocument(inputFilename)
                    ' if PDF document does not have interactive form
                    If document.InteractiveForm Is Nothing Then
                            ' create the interactive form in document
                            document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
                    End If
    
                    ' specify that document contains signatures
                    document.InteractiveForm.SignatureFlags = Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentSignatureFlags.SignaturesExist Or Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentSignatureFlags.AppendOnly
    
                    ' specify that the viewer application must NOT construct appearance streams and
                    ' appearance properties for widget annotations in the document
                    document.InteractiveForm.NeedAppearances = False
    
                    ' PDF page on which signature will be placed
                    Dim page As Vintasoft.Imaging.Pdf.Tree.PdfPage = document.Pages(0)
    
                    ' calculate the signature field rectangle (field will be placed in the center of page)
                    Dim signatureRect As New System.Drawing.RectangleF()
                    signatureRect.Width = page.MediaBox.Width / 5
                    signatureRect.Height = signatureRect.Width / 3
                    signatureRect.X = page.MediaBox.X + (page.MediaBox.Width - signatureRect.Width) / 2
                    signatureRect.Y = page.MediaBox.Y + (page.MediaBox.Height - signatureRect.Height) / 2
    
    
                    ' create PKCS#7 signature
                    Dim signature As Vintasoft.Imaging.Pdf.Tree.DigitalSignatures.PdfPkcsSignature = Vintasoft.Imaging.Pdf.Tree.DigitalSignatures.PdfPkcsSignature.CreatePkcs7Signature(certificate)
    
                    ' create signature info
                    Dim signatureInfo As New Vintasoft.Imaging.Pdf.Tree.DigitalSignatures.PdfSignatureInformation(document, signature)
                    signatureInfo.SignerName = certificate.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, False)
                    signatureInfo.Reason = "Test signing"
                    signatureInfo.Location = System.Globalization.CultureInfo.CurrentCulture.EnglishName
                    signatureInfo.SigningTime = System.DateTime.Now
    
                    ' create the signature field
                    Dim signatureField As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormSignatureField(document, "MySignature1", signatureRect)
    
                    ' set the signature information
                    signatureField.SignatureInfo = signatureInfo
    
                    ' create the signature appearance
                    Using g As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = signatureField.CreateAppearanceGraphics()
                            ' signature text
                            Dim signatureText As String = String.Format("Digitally signed by" & vbLf & "{0}", signatureInfo.SignerName)
    
                            ' signature appearance rect
                            Dim rect As New System.Drawing.RectangleF(System.Drawing.PointF.Empty, signatureField.Annotation.Rectangle.Size)
    
                            ' draw background
                            g.FillRectangle(New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.FromArgb(255, System.Drawing.Color.Lime)), rect)
    
                            ' padding
                            rect.Inflate(-rect.Height / 10, -rect.Height / 10)
    
                            ' create TimesRoman font
                            Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
    
                            ' measure font size
                            Dim fontSize As Single = g.MeasureFontSize(signatureText, font, rect.Width, rect.Height)
    
                            ' draw signture text
                            g.DrawString(signatureText, font, fontSize, New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black), rect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, _
                                    False)
                    End Using
    
                    ' add signature field to the interactive form of document
                    document.InteractiveForm.Fields.Add(signatureField)
    
                    ' if PDF page does not have annotations
                    If page.Annotations Is Nothing Then
                            ' create an empty annotation collection for page
                            page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
                    End If
                    ' add widget annotation of signature field to the annotation collection of page
                    page.Annotations.Add(signatureField.Annotation)
    
                    ' if PDF document can be converted
                    If converter Is Nothing Then
                            If inputFilename = outputFilename Then
                                    ' sign PDF document and save changes in PDF document
                                    document.SaveChanges()
                            Else
                                    ' sign PDF document and save PDF document to the output file
                                    document.Save(outputFilename)
                            End If
                    Else
                            If inputFilename <> outputFilename Then
                                    Dim pdfAConverter As Vintasoft.Imaging.Pdf.Processing.PdfA.PdfAConverter = DirectCast(converter, Vintasoft.Imaging.Pdf.Processing.PdfA.PdfAConverter)
                                    pdfAConverter.OutputFilename = outputFilename
                            End If
    
                            ' sign and convert PDF document
                            converter.Convert(document)
                    End If
            End Using
    End Sub
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Pdf
    
    /// <summary>
    /// Signs a PDF or PDF/A document using specified certificate.
    /// </summary>
    /// <param name="inputFilename">The filename of input PDF document.</param>
    /// <param name="outputFilename">The filename of output PDF document.</param>
    /// <param name="certificate">The certificate that should be used
    /// for signing the input PDF document.</param>
    public static void SignDocument(
        string inputFilename,
        string outputFilename,
        System.Security.Cryptography.X509Certificates.X509Certificate2 certificate,
        Vintasoft.Imaging.Pdf.PdfDocumentConformance conformance)
    {
        Vintasoft.Imaging.Pdf.Processing.PdfDocumentConverter converter = null;
        // if PDF document conformance is specified
        if (conformance != Vintasoft.Imaging.Pdf.PdfDocumentConformance.Undefined)
        {
            // create PDF document converter
            converter = Vintasoft.Imaging.Pdf.Processing.PdfDocumentConverter.Create(conformance);
            // if PDF document converter is not found
            if (converter == null)
            {
                string message = string.Format("Unsupported {0} conformance.", conformance);
                throw new System.ArgumentOutOfRangeException(message);
            }
        }
    
        // open PDF document
        using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument(inputFilename))
        {
            // if PDF document does not have interactive form
            if (document.InteractiveForm == null)
            {
                // create the interactive form in document
                document.InteractiveForm = new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
            }
    
            // specify that document contains signatures
            document.InteractiveForm.SignatureFlags =
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentSignatureFlags.SignaturesExist | 
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentSignatureFlags.AppendOnly;
    
            // specify that the viewer application must NOT construct appearance streams and
            // appearance properties for widget annotations in the document
            document.InteractiveForm.NeedAppearances = false;
    
            // PDF page on which signature will be placed
            Vintasoft.Imaging.Pdf.Tree.PdfPage page = document.Pages[0];
    
            // calculate the signature field rectangle (field will be placed in the center of page)
            System.Drawing.RectangleF signatureRect = new System.Drawing.RectangleF();
            signatureRect.Width = page.MediaBox.Width / 5;
            signatureRect.Height = signatureRect.Width / 3;
            signatureRect.X = page.MediaBox.X + (page.MediaBox.Width - signatureRect.Width) / 2;
            signatureRect.Y = page.MediaBox.Y + (page.MediaBox.Height - signatureRect.Height) / 2;
    
    
            // create PKCS#7 signature
            Vintasoft.Imaging.Pdf.Tree.DigitalSignatures.PdfPkcsSignature signature = 
                Vintasoft.Imaging.Pdf.Tree.DigitalSignatures.PdfPkcsSignature.CreatePkcs7Signature(certificate);
    
            // create signature info
            Vintasoft.Imaging.Pdf.Tree.DigitalSignatures.PdfSignatureInformation signatureInfo = 
                new Vintasoft.Imaging.Pdf.Tree.DigitalSignatures.PdfSignatureInformation(document, signature);
            signatureInfo.SignerName = certificate.GetNameInfo(
                System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false);
            signatureInfo.Reason = "Test signing";
            signatureInfo.Location = System.Globalization.CultureInfo.CurrentCulture.EnglishName;
            signatureInfo.SigningTime = System.DateTime.Now;
    
            // create the signature field
            Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormSignatureField signatureField =
                new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormSignatureField(document, "MySignature1", signatureRect);
    
            // set the signature information
            signatureField.SignatureInfo = signatureInfo;
    
            // create the signature appearance
            using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics g = signatureField.CreateAppearanceGraphics())
            {
                // signature text
                string signatureText = string.Format("Digitally signed by\n{0}",
                    signatureInfo.SignerName);
    
                // signature appearance rect
                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(
                    System.Drawing.PointF.Empty,
                    signatureField.Annotation.Rectangle.Size);
    
                // draw background
                g.FillRectangle(new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(
                    System.Drawing.Color.FromArgb(255, System.Drawing.Color.Lime)), rect);
    
                // padding
                rect.Inflate(-rect.Height / 10, -rect.Height / 10);
    
                // create TimesRoman font
                Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = document.FontManager.GetStandardFont(
                    Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
    
                // measure font size
                float fontSize = g.MeasureFontSize(signatureText, font, rect.Width, rect.Height);
    
                // draw signture text
                g.DrawString(
                    signatureText,
                    font, fontSize, new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black),
                    rect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, false);
            }
    
            // add signature field to the interactive form of document
            document.InteractiveForm.Fields.Add(signatureField);
    
            // if PDF page does not have annotations
            if (page.Annotations == null)
                // create an empty annotation collection for page
                page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
            // add widget annotation of signature field to the annotation collection of page
            page.Annotations.Add(signatureField.Annotation);
    
            // if PDF document can be converted
            if (converter == null)
            {
                if (inputFilename == outputFilename)
                {
                    // sign PDF document and save changes in PDF document
                    document.SaveChanges();
                }
                else
                {
                    // sign PDF document and save PDF document to the output file
                    document.Save(outputFilename);
                }
            }
            else
            {
                if (inputFilename != outputFilename)
                {
                    Vintasoft.Imaging.Pdf.Processing.PdfA.PdfAConverter pdfAConverter = 
                        (Vintasoft.Imaging.Pdf.Processing.PdfA.PdfAConverter)converter;
                    pdfAConverter.OutputFilename = outputFilename;
                }
    
                // sign and convert PDF document
                converter.Convert(document);
            }
        }
    }
                    
    


    Changing the value of form field

    To change a value of a form field is necessary to do the following:

    To change the default value of a form field is necessary to do the following:

    Here is an example that demonstrates how to change the value of a text field:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging.Pdf
    
    ''' <summary>
    ''' Changes the text field value.
    ''' </summary>
    ''' <param name="document">The PDF document.</param>
    ''' <param name="fieldFullName">Full name of the field.</param>
    ''' <param name="newValue">The new value of the field.</param>
    ''' <returns>
    ''' <b>true</b> - field value is changed successfully;
    ''' <b>false</b> - field value is NOT changed.
    ''' </returns>
    Public Shared Function ChangeTextFieldValue(document As Vintasoft.Imaging.Pdf.PdfDocument, fieldFullName As String, newValue As String) As Boolean
            ' if PDF document has PDF interactive form
            If document.InteractiveForm IsNot Nothing Then
                    ' find field by name
                    Dim field As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField = document.InteractiveForm.FindField(fieldFullName)
                    ' if field is found
                    If field IsNot Nothing Then
                            Dim textField As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField = TryCast(field, Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField)
                            ' if field is text field
                            If textField IsNot Nothing Then
                                    ' set new value of the field
                                    textField.Value = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextFieldStringValue(document, newValue)
    
                                    Return True
                            End If
                    End If
            End If
            Return False
    End Function
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging.Pdf
    
    /// <summary>
    /// Changes the text field value.
    /// </summary>
    /// <param name="document">The PDF document.</param>
    /// <param name="fieldFullName">Full name of the field.</param>
    /// <param name="newValue">The new value of the field.</param>
    /// <returns>
    /// <b>true</b> - field value is changed successfully;
    /// <b>false</b> - field value is NOT changed.
    /// </returns>
    public static bool ChangeTextFieldValue(
        Vintasoft.Imaging.Pdf.PdfDocument document,
        string fieldFullName,
        string newValue)
    {
        // if PDF document has PDF interactive form
        if (document.InteractiveForm != null)
        {
            // find field by name
            Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField field = 
                document.InteractiveForm.FindField(fieldFullName);
            // if field is found
            if (field != null)
            {
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField textField = 
                    field as Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField;
                // if field is text field
                if (textField != null)
                {
                    // set new value of the field
                    textField.Value = 
                        new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextFieldStringValue(document, newValue);
    
                    return true;
                }
            }
        }
        return false;
    }
                    
    


    Removal of form field

    The form field can be removed using PdfDocumentInteractiveForm.RemoveField method in case the full name of field is known. The method removes the field, its child fields and all fields annotations.
    Also the field can be removed using PdfInteractiveFormField.Remove method . The method removes the field, its child fields and all fields annotations.

    Here is an example that demonstrates how to remove a field by name:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging.Pdf
    
    ''' <summary>
    ''' Removes an interactive field from interactive form of PDF document.
    ''' </summary>
    ''' <param name="pdfFilename">The filename of PDF document.</param>
    ''' <param name="fullyQualifiedFieldName">The name of field.</param>
    Public Shared Sub RemoveFieldFromPdfInteractiveForm(pdfFilename As String, fullyQualifiedFieldName As String)
            ' open PDF document
            Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
                    ' if PDF document has interactive form
                    If document.InteractiveForm IsNot Nothing Then
                            ' get reference to the interactive form
                            Dim form As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm = document.InteractiveForm
    
                            ' remove field from interactive form
                            form.RemoveField(fullyQualifiedFieldName)
    
                            ' save changes to a file
                            document.SaveChanges()
                    End If
            End Using
    End Sub
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging.Pdf
    
    /// <summary>
    /// Removes an interactive field from interactive form of PDF document.
    /// </summary>
    /// <param name="pdfFilename">The filename of PDF document.</param>
    /// <param name="fullyQualifiedFieldName">The name of field.</param>
    public static void RemoveFieldFromPdfInteractiveForm(string pdfFilename, string fullyQualifiedFieldName)
    {
        // open PDF document
        using (Vintasoft.Imaging.Pdf.PdfDocument document = 
            new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
        {
            // if PDF document has interactive form
            if (document.InteractiveForm != null)
            {
                // get reference to the interactive form
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm form = document.InteractiveForm;
    
                // remove field from interactive form
                form.RemoveField(fullyQualifiedFieldName);
    
                // save changes to a file
                document.SaveChanges();
            }
        }
    }
                    
    


    Actions of form field

    PdfInteractiveFormField.AdditionalActions property allows to define the following actions connected with the form field data:

    PdfAnnotation.ActivateAction and PdfAnnotation.AdditionalActions properties allow to define the actions, connected with the visual appearance of form. For example, the action that should be performed if the mouse button is clicked above annotation or the action that should be performed when the page with annotation has become visible.

    The interactive form may include a field, the value of which must be recalculated if the value of any other field has changed. PdfDocumentInteractiveForm.CalculationOrder property allows to define a list of fields selected for recalculation. The recalculation is performed in order of fields in the property.

    To recalculate the field value dynamically is necessary to do the following:

    Here is an example that demonstrates how to create a calculator (a group of fields with JavaScript code) and add the calculator into a form of PDF document:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Pdf
    
    ''' <summary>
    ''' Creates a PDF document with calculated interactive form field.
    ''' </summary>
    ''' <param name="filename">The filename.</param>
    Public Shared Sub CreateDocumentWithCalculatedInteractiveFormField(filename As String)
            ' create PDF document
            Using document As New Vintasoft.Imaging.Pdf.PdfDocument()
                    ' create interactive form in PDF document
                    document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
    
                    ' specify that the viewer application must construct appearance streams and
                    ' appearance properties for all widget annotations
                    document.InteractiveForm.NeedAppearances = True
    
                    ' font and font size
                    Dim fontSize As Single = 12
                    Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
    
                    ' create an empty page
                    Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A4)
                    ' add page to the document
                    document.Pages.Add(page)
    
                    Dim width As Single = 60
                    Dim height As Single = 40
                    ' create a rectangle that defines the object (first field) position on PDF page
                    Dim rect As New System.Drawing.RectangleF((page.Size.Width - width * 5) / 2, ((page.Size.Height - height) / 3) * 2, width, height)
    
                    ' open PdfGraphics on page
                    Using graphics As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = page.GetGraphics()
                            ' create calculator field: group of three fields
                            Dim calculator As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField(document, "Calculator")
                            calculator.SetTextDefaultAppearance(font, fontSize * 1.5F, System.Drawing.Color.Black)
                            calculator.TextQuadding = Vintasoft.Imaging.Pdf.Tree.InteractiveForms.TextQuaddingType.Centered
    
                            ' create the border style
                            Dim borderStyle As New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document)
                            borderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Inset
                            borderStyle.Width = 1
    
                            ' create the appearance characteristics
                            Dim appearanceCharacteristics As New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document)
                            appearanceCharacteristics.BorderColor = System.Drawing.Color.Gray
    
                            ' create the left text box
                            Dim textField As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField(document, "Left", rect, "2")
                            textField.DefaultValue = textField.Value
                            textField.Annotation.BorderStyle = borderStyle
                            textField.Annotation.AppearanceCharacteristics = appearanceCharacteristics
                            ' add the left text box to the calculator
                            calculator.Kids.Add(textField)
    
                            ' update the rectangle that defines the object position on PDF page
                            rect.X += rect.Width
    
                            ' draw the symbol '+' on the page
                            graphics.DrawString("+", font, fontSize * 1.5F, New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black), rect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, _
                                    False)
    
                            ' update the rectangle that defines the object position on PDF page
                            rect.X += rect.Width
    
                            ' create the right text box
                            textField = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField(document, "Right", rect, "3")
                            textField.DefaultValue = textField.Value
                            textField.Annotation.BorderStyle = borderStyle
                            textField.Annotation.AppearanceCharacteristics = appearanceCharacteristics
                            ' add the right text box to the calculator
                            calculator.Kids.Add(textField)
    
                            ' update the rectangle that defines the object position on PDF page
                            rect.X += rect.Width
    
                            ' draw the symbol '=' on the page
                            graphics.DrawString("=", font, fontSize * 1.5F, New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black), rect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, _
                                    False)
    
                            ' create the calculator program written on JavaScript
                            Dim javaScriptCode As New System.Text.StringBuilder()
                            javaScriptCode.Append("var left = this.getField('Calculator.Left');")
                            javaScriptCode.Append("var right = this.getField('Calculator.Right');")
                            javaScriptCode.Append("var result = this.getField('Calculator.Result');")
                            javaScriptCode.Append("result.value = left.value + right.value;")
                            Dim calculatorProgram As New Vintasoft.Imaging.Pdf.Tree.PdfJavaScriptAction(document, javaScriptCode.ToString())
    
                            ' update the rectangle that defines the object position on PDF page
                            rect.X += rect.Width
    
                            ' create the result text box
                            textField = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField(document, "Result", rect)
                            textField.IsReadOnly = True
                            textField.Annotation.BorderStyle = borderStyle
                            textField.Annotation.AppearanceCharacteristics = appearanceCharacteristics
                            ' set a program that will calculate value of result field
                            textField.AdditionalActions = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldAdditionalActions(document)
                            textField.AdditionalActions.Calculate = calculatorProgram
                            ' specify that calcualtor program must be executed when page is opened
                            textField.Annotation.AdditionalActions.PageOpen = calculatorProgram
                            ' add the result text box to the calculator
                            calculator.Kids.Add(textField)
    
                            ' add result field to the calculated fields (calcualtion order)
                            ' of the document interactive form fields
                            document.InteractiveForm.CalculationOrder = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldList(document)
                            document.InteractiveForm.CalculationOrder.Add(textField)
    
                            ' add field group to the document
                            document.InteractiveForm.Fields.Add(calculator)
    
                            ' add annotations, associated with field group, to the page
                            page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
                            page.Annotations.AddRange(calculator.GetAnnotations())
    
                            ' update appearance of field group
                            calculator.UpdateAppearance()
                    End Using
    
                    ' save the document
                    document.Save(filename)
            End Using
    End Sub
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Pdf
    
    /// <summary>
    /// Creates a PDF document with calculated interactive form field.
    /// </summary>
    /// <param name="filename">The filename.</param>
    public static void CreateDocumentWithCalculatedInteractiveFormField(string filename)
    {
        // create PDF document
        using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument())
        {
            // create interactive form in PDF document
            document.InteractiveForm = 
                new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
    
            // specify that the viewer application must construct appearance streams and
            // appearance properties for all widget annotations
            document.InteractiveForm.NeedAppearances = true;
    
            // font and font size
            float fontSize = 12;
            Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = 
                document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
    
            // create an empty page
            Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
                document, Vintasoft.Imaging.PaperSizeKind.A4);
            // add page to the document
            document.Pages.Add(page);
    
            float width = 60;
            float height = 40;
            // create a rectangle that defines the object (first field) position on PDF page
            System.Drawing.RectangleF rect = new System.Drawing.RectangleF(
                (page.Size.Width - width * 5) / 2,
                ((page.Size.Height - height) / 3) * 2,
                width, height);
    
            // open PdfGraphics on page
            using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics graphics = page.GetGraphics())
            {
                // create calculator field: group of three fields
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField calculator =
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField(document, "Calculator");
                calculator.SetTextDefaultAppearance(font, fontSize * 1.5f, System.Drawing.Color.Black);
                calculator.TextQuadding = Vintasoft.Imaging.Pdf.Tree.InteractiveForms.TextQuaddingType.Centered;
    
                // create the border style
                Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle borderStyle = 
                    new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document);
                borderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Inset;
                borderStyle.Width = 1;
    
                // create the appearance characteristics
                Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics appearanceCharacteristics =
                    new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document);
                appearanceCharacteristics.BorderColor = System.Drawing.Color.Gray;
    
                // create the left text box
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField textField =
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField(document, "Left", rect, "2");
                textField.DefaultValue = textField.Value;
                textField.Annotation.BorderStyle = borderStyle;
                textField.Annotation.AppearanceCharacteristics = appearanceCharacteristics;
                // add the left text box to the calculator
                calculator.Kids.Add(textField);
    
                // update the rectangle that defines the object position on PDF page
                rect.X += rect.Width;
    
                // draw the symbol '+' on the page
                graphics.DrawString("+", font, fontSize * 1.5f,
                    new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black), rect, 
                    Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, false);
    
                // update the rectangle that defines the object position on PDF page
                rect.X += rect.Width;
    
                // create the right text box
                textField = new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField(document, "Right", rect, "3");
                textField.DefaultValue = textField.Value;
                textField.Annotation.BorderStyle = borderStyle;
                textField.Annotation.AppearanceCharacteristics = appearanceCharacteristics;
                // add the right text box to the calculator
                calculator.Kids.Add(textField);
    
                // update the rectangle that defines the object position on PDF page
                rect.X += rect.Width;
    
                // draw the symbol '=' on the page
                graphics.DrawString("=", font, fontSize * 1.5f,
                    new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black), rect, 
                    Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, false);
    
                // create the calculator program written on JavaScript
                System.Text.StringBuilder javaScriptCode = new System.Text.StringBuilder();
                javaScriptCode.Append("var left = this.getField('Calculator.Left');");
                javaScriptCode.Append("var right = this.getField('Calculator.Right');");
                javaScriptCode.Append("var result = this.getField('Calculator.Result');");
                javaScriptCode.Append("result.value = left.value + right.value;");
                Vintasoft.Imaging.Pdf.Tree.PdfJavaScriptAction calculatorProgram =
                    new Vintasoft.Imaging.Pdf.Tree.PdfJavaScriptAction(document, javaScriptCode.ToString());
    
                // update the rectangle that defines the object position on PDF page
                rect.X += rect.Width;
    
                // create the result text box
                textField = new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField(document, "Result", rect);
                textField.IsReadOnly = true;
                textField.Annotation.BorderStyle = borderStyle;
                textField.Annotation.AppearanceCharacteristics = appearanceCharacteristics;
                // set a program that will calculate value of result field
                textField.AdditionalActions = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldAdditionalActions(document);
                textField.AdditionalActions.Calculate = calculatorProgram;
                // specify that calcualtor program must be executed when page is opened
                textField.Annotation.AdditionalActions.PageOpen = calculatorProgram;
                // add the result text box to the calculator
                calculator.Kids.Add(textField);
    
                // add result field to the calculated fields (calcualtion order)
                // of the document interactive form fields
                document.InteractiveForm.CalculationOrder = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldList(document);
                document.InteractiveForm.CalculationOrder.Add(textField);
    
                // add field group to the document
                document.InteractiveForm.Fields.Add(calculator);
    
                // add annotations, associated with field group, to the page
                page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
                page.Annotations.AddRange(calculator.GetAnnotations());
    
                // update appearance of field group
                calculator.UpdateAppearance();
            }
    
            // save the document
            document.Save(filename);
        }
    }
                    
    


    Here is an example that demonstrates how to send the form data to the specified URL:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Pdf
    
    ''' <summary>
    ''' Adds a submit button to a PDF document.
    ''' </summary>
    ''' <param name="pdfFilename">The filename of PDF document.</param>
    ''' <param name="url">URL to submit form.</param>
    Public Shared Sub AddSubmitFormButton(pdfFilename As String, url As String)
            ' open PDF document
            Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
                    ' create new PDF page
                    Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A6)
                    ' add page to PDF document
                    document.Pages.Add(page)
    
                    ' create a button and add button to PDF page
                    Dim button As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField = CreateButtonAndAddToPdfPage(page, "Submit")
    
                    ' create submit action
                    Dim action As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfSubmitFormAction(document)
                    ' specify that all fields of document must be submitted
                    action.Fields = document.InteractiveForm.Fields
                    ' specify submit URL
                    action.Url = url
                    ' specify the submit format
                    action.SubmitFormat = Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldSubmitFormat.HTML
    
                    ' set the button action
                    button.Annotation.ActivateAction = action
    
                    ' save changes to a file
                    document.SaveChanges()
            End Using
    End Sub
    
    ''' <summary>
    ''' Creates button and adds it to PDF page.
    ''' </summary>
    ''' <param name="page">PDF page.</param>
    ''' <param name="caption">Caption of button.</param>
    Public Shared Function CreateButtonAndAddToPdfPage(page As Vintasoft.Imaging.Pdf.Tree.PdfPage, caption As String) As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField
            ' PDF document
            Dim document As Vintasoft.Imaging.Pdf.PdfDocument = page.Document
    
            ' button position on PDF page
            Dim rect As New System.Drawing.RectangleF(50, page.Size.Height - 150, 200, 100)
    
            ' create button
            Dim button As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField(document, "button", rect)
            ' set the border style
            button.Annotation.BorderStyle = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document)
            button.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled
            button.Annotation.BorderStyle.Width = 2
            ' set the appearance characteristics
            button.Annotation.AppearanceCharacteristics = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document)
            button.Annotation.AppearanceCharacteristics.BackgroundColor = System.Drawing.Color.LightGray
            button.Annotation.AppearanceCharacteristics.ButtonNormalCaption = caption
            ' set the text default appearance
            Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
            button.SetTextDefaultAppearance(font, 15F, System.Drawing.Color.Black)
    
            ' if PDF document does NOT have interactive form
            If document.InteractiveForm Is Nothing Then
                    ' create interactive form in PDF document
                    document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
            End If
            ' add button to the interactive form of PDF document
            document.InteractiveForm.Fields.Add(button)
    
            ' if PDF page does NOT have annotation list
            If page.Annotations Is Nothing Then
                    ' create annotation list for PDF page
                    page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
            End If
            ' add the button annotation to PDF page
            page.Annotations.Add(button.Annotation)
    
            ' update field appearance
            button.UpdateAppearance()
    
            ' return the button
            Return button
    End Function
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Pdf
    
    /// <summary>
    /// Adds a submit button to a PDF document.
    /// </summary>
    /// <param name="pdfFilename">The filename of PDF document.</param>
    /// <param name="url">URL to submit form.</param>
    public static void AddSubmitFormButton(string pdfFilename, string url)
    {
        // open PDF document
        using (Vintasoft.Imaging.Pdf.PdfDocument document = 
            new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
        {
            // create new PDF page
            Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
                document, Vintasoft.Imaging.PaperSizeKind.A6);
            // add page to PDF document
            document.Pages.Add(page);
    
            // create a button and add button to PDF page
            Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField button = 
                CreateButtonAndAddToPdfPage(page, "Submit");
    
            // create submit action
            Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfSubmitFormAction action = 
                new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfSubmitFormAction(document);
            // specify that all fields of document must be submitted
            action.Fields = document.InteractiveForm.Fields;
            // specify submit URL
            action.Url = url;
            // specify the submit format
            action.SubmitFormat = Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldSubmitFormat.HTML;
    
            // set the button action
            button.Annotation.ActivateAction = action;
    
            // save changes to a file
            document.SaveChanges();
        }
    }
    
    /// <summary>
    /// Creates button and adds it to PDF page.
    /// </summary>
    /// <param name="page">PDF page.</param>
    /// <param name="caption">Caption of button.</param>
    public static Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField CreateButtonAndAddToPdfPage(
        Vintasoft.Imaging.Pdf.Tree.PdfPage page, string caption)
    {
        // PDF document
        Vintasoft.Imaging.Pdf.PdfDocument document = page.Document;
    
        // button position on PDF page
        System.Drawing.RectangleF rect = new System.Drawing.RectangleF(50, page.Size.Height - 150, 200, 100);
    
        // create button
        Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField button = 
            new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField(document, "button", rect);
        // set the border style
        button.Annotation.BorderStyle = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document);
        button.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled;
        button.Annotation.BorderStyle.Width = 2;
        // set the appearance characteristics
        button.Annotation.AppearanceCharacteristics = 
            new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document);
        button.Annotation.AppearanceCharacteristics.BackgroundColor = System.Drawing.Color.LightGray;
        button.Annotation.AppearanceCharacteristics.ButtonNormalCaption = caption;
        // set the text default appearance
        Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = 
            document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
        button.SetTextDefaultAppearance(font, 15f, System.Drawing.Color.Black);
    
        // if PDF document does NOT have interactive form
        if (document.InteractiveForm == null)
            // create interactive form in PDF document
            document.InteractiveForm = new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
        // add button to the interactive form of PDF document
        document.InteractiveForm.Fields.Add(button);
        
        // if PDF page does NOT have annotation list
        if (page.Annotations == null)
            // create annotation list for PDF page
            page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
        // add the button annotation to PDF page
        page.Annotations.Add(button.Annotation);
        
        // update field appearance
        button.UpdateAppearance();
    
        // return the button
        return button;
    }
                    
    


    Here is an example that demonstrates how to load a form data from the specified file:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Pdf
    
    ''' <summary>
    ''' Adds a form import button to a PDF document.
    ''' </summary>
    ''' <param name="pdfFilename">The filename of PDF document.</param>
    ''' <param name="loadFilename">The filename of import data file.</param>
    Public Shared Sub AddFormImportButton(pdfFilename As String, loadFilename As String)
            ' open PDF document
            Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
                    ' create PDF page
                    Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A6)
                    ' add page to the PDF document
                    document.Pages.Add(page)
    
                    ' create a button and add button to PDF page
                    Dim button As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField = CreateButtonAndAddToPdfPage(page, "Load form")
    
                    ' create reference to a file with data that should be imported
                    Dim fileReference As New Vintasoft.Imaging.Pdf.Tree.PdfFileReferenceSpecification(document, loadFilename)
    
                    ' create the form import action
                    Dim action As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormImportDataAction(document, fileReference)
                    ' specify that all fields of document must be imported
                    action.Fields = document.InteractiveForm.Fields
    
                    ' set the button action
                    button.Annotation.ActivateAction = action
    
                    ' save changes to a file
                    document.SaveChanges()
            End Using
    End Sub
    
    ''' <summary>
    ''' Creates button and adds it to PDF page.
    ''' </summary>
    ''' <param name="page">PDF page.</param>
    ''' <param name="caption">Caption of button.</param>
    Public Shared Function CreateButtonAndAddToPdfPage(page As Vintasoft.Imaging.Pdf.Tree.PdfPage, caption As String) As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField
            ' PDF document
            Dim document As Vintasoft.Imaging.Pdf.PdfDocument = page.Document
    
            ' button position on PDF page
            Dim rect As New System.Drawing.RectangleF(50, page.Size.Height - 150, 200, 100)
    
            ' create button
            Dim button As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField(document, "button", rect)
            ' set the border style
            button.Annotation.BorderStyle = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document)
            button.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled
            button.Annotation.BorderStyle.Width = 2
            ' set the appearance characteristics
            button.Annotation.AppearanceCharacteristics = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document)
            button.Annotation.AppearanceCharacteristics.BackgroundColor = System.Drawing.Color.LightGray
            button.Annotation.AppearanceCharacteristics.ButtonNormalCaption = caption
            ' set the text default appearance
            Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
            button.SetTextDefaultAppearance(font, 15F, System.Drawing.Color.Black)
    
            ' if PDF document does NOT have interactive form
            If document.InteractiveForm Is Nothing Then
                    ' create interactive form in PDF document
                    document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
            End If
            ' add button to the interactive form of PDF document
            document.InteractiveForm.Fields.Add(button)
    
            ' if PDF page does NOT have annotation list
            If page.Annotations Is Nothing Then
                    ' create annotation list for PDF page
                    page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
            End If
            ' add the button annotation to PDF page
            page.Annotations.Add(button.Annotation)
    
            ' update field appearance
            button.UpdateAppearance()
    
            ' return the button
            Return button
    End Function
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Pdf
    
    /// <summary>
    /// Adds a form import button to a PDF document.
    /// </summary>
    /// <param name="pdfFilename">The filename of PDF document.</param>
    /// <param name="loadFilename">The filename of import data file.</param>
    public static void AddFormImportButton(string pdfFilename, string loadFilename)
    {
        // open PDF document
        using (Vintasoft.Imaging.Pdf.PdfDocument document = 
            new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
        {
            // create PDF page
            Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
                document, Vintasoft.Imaging.PaperSizeKind.A6);
            // add page to the PDF document
            document.Pages.Add(page);
    
            // create a button and add button to PDF page
            Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField button = 
                CreateButtonAndAddToPdfPage(page, "Load form");
    
            // create reference to a file with data that should be imported
            Vintasoft.Imaging.Pdf.Tree.PdfFileReferenceSpecification fileReference = 
                new Vintasoft.Imaging.Pdf.Tree.PdfFileReferenceSpecification(document, loadFilename);
    
            // create the form import action
            Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormImportDataAction action = 
                new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormImportDataAction(document, fileReference);
            // specify that all fields of document must be imported
            action.Fields = document.InteractiveForm.Fields;
            
            // set the button action
            button.Annotation.ActivateAction = action;
    
            // save changes to a file
            document.SaveChanges();
        }
    }
    
    /// <summary>
    /// Creates button and adds it to PDF page.
    /// </summary>
    /// <param name="page">PDF page.</param>
    /// <param name="caption">Caption of button.</param>
    public static Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField CreateButtonAndAddToPdfPage(
        Vintasoft.Imaging.Pdf.Tree.PdfPage page, string caption)
    {
        // PDF document
        Vintasoft.Imaging.Pdf.PdfDocument document = page.Document;
    
        // button position on PDF page
        System.Drawing.RectangleF rect = new System.Drawing.RectangleF(50, page.Size.Height - 150, 200, 100);
    
        // create button
        Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField button = 
            new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField(document, "button", rect);
        // set the border style
        button.Annotation.BorderStyle = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document);
        button.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled;
        button.Annotation.BorderStyle.Width = 2;
        // set the appearance characteristics
        button.Annotation.AppearanceCharacteristics = 
            new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document);
        button.Annotation.AppearanceCharacteristics.BackgroundColor = System.Drawing.Color.LightGray;
        button.Annotation.AppearanceCharacteristics.ButtonNormalCaption = caption;
        // set the text default appearance
        Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = document.FontManager.GetStandardFont(
            Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
        button.SetTextDefaultAppearance(font, 15f, System.Drawing.Color.Black);
    
        // if PDF document does NOT have interactive form
        if (document.InteractiveForm == null)
            // create interactive form in PDF document
            document.InteractiveForm = new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
        // add button to the interactive form of PDF document
        document.InteractiveForm.Fields.Add(button);
    
        // if PDF page does NOT have annotation list
        if (page.Annotations == null)
            // create annotation list for PDF page
            page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
        // add the button annotation to PDF page
        page.Annotations.Add(button.Annotation);
    
        // update field appearance
        button.UpdateAppearance();
    
        // return the button
        return button;
    }
                    
    


    Importing and exporting data of the document interactive form

    Using the PdfInteractiveFormDataXfdfCodec class is possible to export/import the field values of interactive form in XFDF format.

    Here is an example that demonstrates how to export/import the data of interactive form of PDF document:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging.Pdf
    
    ''' <summary>
    ''' Exports the form data to the specified stream.
    ''' </summary>
    ''' <param name="document">The PDF document.</param>
    ''' <param name="stream">The stream, where form data must be exported.</param>
    Public Shared Sub ExportFormData(document As Vintasoft.Imaging.Pdf.PdfDocument, stream As System.IO.Stream)
            If document.InteractiveForm IsNot Nothing Then
                    Dim xfdfCodec As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormDataXfdfCodec()
                    xfdfCodec.ExportFieldsWithoutValue = False
                    xfdfCodec.Export(document.InteractiveForm, stream)
            End If
    End Sub
    
    ''' <summary>
    ''' Imports the form data from the specified stream.
    ''' </summary>
    ''' <param name="document">The PDF document.</param>
    ''' <param name="stream">The stream from which the form data must be imported.</param>
    Public Shared Sub ImportFormData(document As Vintasoft.Imaging.Pdf.PdfDocument, stream As System.IO.Stream)
            If document.InteractiveForm IsNot Nothing Then
                    Dim xfdfCodec As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormDataXfdfCodec()
                    xfdfCodec.Import(document.InteractiveForm, stream)
                    document.InteractiveForm.UpdateAppearances()
            End If
    End Sub
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging.Pdf
    
    /// <summary>
    /// Exports the form data to the specified stream.
    /// </summary>
    /// <param name="document">The PDF document.</param>
    /// <param name="stream">The stream, where form data must be exported.</param>
    public static void ExportFormData(
        Vintasoft.Imaging.Pdf.PdfDocument document, 
        System.IO.Stream stream)
    {
        if (document.InteractiveForm != null)
        {
            Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormDataXfdfCodec xfdfCodec = 
                new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormDataXfdfCodec();
            xfdfCodec.ExportFieldsWithoutValue = false;
            xfdfCodec.Export(document.InteractiveForm, stream);
        }
    }
    
    /// <summary>
    /// Imports the form data from the specified stream.
    /// </summary>
    /// <param name="document">The PDF document.</param>
    /// <param name="stream">The stream from which the form data must be imported.</param>
    public static void ImportFormData(
        Vintasoft.Imaging.Pdf.PdfDocument document, 
        System.IO.Stream stream)
    {
        if (document.InteractiveForm != null)
        {
            Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormDataXfdfCodec xfdfCodec = 
                new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormDataXfdfCodec();
            xfdfCodec.Import(document.InteractiveForm, stream);
            document.InteractiveForm.UpdateAppearances();
        }
    }