SelectPdf for .NET - Pdf Form Fields Filling - VB.NET / ASP.NET Sample

This sample shows how to use SelectPdf Library for .NET to load an existing document that contains an AcroForm PDF form, fill some of the fields and save the document.

Here is our test pdf document that contains a PDF form:
Test form

Click on the "Create PDF" button below to see the result.

Sample Code Vb.Net

Public Class pdf_form_filling
    Inherits System.Web.UI.Page

    Protected Sub BtnCreatePdf_Click(sender As Object, e As EventArgs)
        ' the initial file
        Dim file As String = Server.MapPath("~/files/w-9.pdf")

        ' load the pdf form manager
        Dim form As New PdfFormManager()

        ' fill some fields
        Dim name As PdfFormFieldTextBox = _
            TryCast(form.Fields("f1_1"), PdfFormFieldTextBox)
        name.Text = "This is my name"

        Dim businessName As PdfFormFieldTextBox = _
            TryCast(form.Fields("f1_2"), PdfFormFieldTextBox)
        businessName.Text = "This is my business name"

        Dim clasifIndividual As PdfFormFieldCheckBox = _
            TryCast(form.Fields("c1_1"), PdfFormFieldCheckBox)
        clasifIndividual.Checked = True

        Dim address As PdfFormFieldTextBox = _
            TryCast(form.Fields("f1_7"), PdfFormFieldTextBox)
        address.Text = "This is my address"

        Dim city As PdfFormFieldTextBox = _
            TryCast(form.Fields("f1_8"), PdfFormFieldTextBox)
        city.Text = "This is my city"

        Dim employer1 As PdfFormFieldTextBox = _
            TryCast(form.Fields("f1_14"), PdfFormFieldTextBox)
        employer1.Text = "XX"

        Dim employer2 As PdfFormFieldTextBox = _
            TryCast(form.Fields("f1_15"), PdfFormFieldTextBox)
        employer2.Text = "1234567"

        Dim ssn1 As PdfFormFieldTextBox = _
            TryCast(form.Fields("f1_11"), PdfFormFieldTextBox)
        ssn1.Text = "123"

        Dim ssn2 As PdfFormFieldTextBox = _
            TryCast(form.Fields("f1_12"), PdfFormFieldTextBox)
        ssn2.Text = "45"

        Dim ssn3 As PdfFormFieldTextBox = _
            TryCast(form.Fields("f1_13"), PdfFormFieldTextBox)
        ssn3.Text = "6789"

        ' save pdf document
        form.Save(Response, False, "Sample.pdf")

        ' close pdf document
    End Sub

End Class