Fill existing form

Docotic.Pdf Library Help > Samples > Forms and Annotations > Fill existing form

This sample shows how to fill forms in existing PDF documents.

When you open a PDF document with a form, you can access and modify document widgets (annotations and controls).

using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
    public static class FillForm
        public static void Main()
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit
            // for more information.

            string pathToFile = "FillForm.pdf";

            using (PdfDocument pdf = new PdfDocument("Sample data/form.pdf"))
                PdfTextBox nameTextBox = (PdfTextBox)pdf.Widgets[0];
                nameTextBox.Text = "Some Name";

                PdfTextBox passwordTextBox = (PdfTextBox)pdf.Widgets[1];
                passwordTextBox.Text = "Password";

                PdfTextBox confimPasswordTextBox = (PdfTextBox)pdf.Widgets[2];
                confimPasswordTextBox.Text = "Password";

                PdfTextBox emailTextBox = (PdfTextBox)pdf.Widgets[3];
                emailTextBox.Text = "";

                PdfCheckBox hideEmailCheckBox = (PdfCheckBox)pdf.Widgets[4];
                hideEmailCheckBox.Checked = true;

                PdfRadioButton secondRadioButton = (PdfRadioButton)pdf.Widgets[6];
                secondRadioButton.Checked = true;

                PdfButton registerButton = (PdfButton)pdf.Widgets[7];
                registerButton.ReadOnly = true;


Visual Basic 
Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class FillForm
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit
            ' for more information.

            Dim pathToFile As String = "FillForm.pdf"

            Using pdf As New PdfDocument("Sample data/form.pdf")

                Dim nameTextBox As PdfTextBox = DirectCast(pdf.Widgets(0), PdfTextBox)
                nameTextBox.Text = "Some Name"

                Dim passwordTextBox As PdfTextBox = DirectCast(pdf.Widgets(1), PdfTextBox)
                passwordTextBox.Text = "Password"

                Dim confimPasswordTextBox As PdfTextBox = DirectCast(pdf.Widgets(2), PdfTextBox)
                confimPasswordTextBox.Text = "Password"

                Dim emailTextBox As PdfTextBox = DirectCast(pdf.Widgets(3), PdfTextBox)
                emailTextBox.Text = ""

                Dim hideEmailCheckBox As PdfCheckBox = DirectCast(pdf.Widgets(4), PdfCheckBox)
                hideEmailCheckBox.Checked = True

                Dim secondRadioButton As PdfRadioButton = DirectCast(pdf.Widgets(6), PdfRadioButton)
                secondRadioButton.Checked = True

                Dim registerButton As PdfButton = DirectCast(pdf.Widgets(7), PdfButton)
                registerButton.[ReadOnly] = True

            End Using

        End Sub
    End Class
End Namespace