How to Start Convert PDF Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

PDF Form VB.NET Library
How to Fill-in Field Data Automatically in VB.NET


How to Automatically Fill in Field Data to PDF in VB.NET Class





In this Visual Basic tutorial, you learn how to fill in Acrobat PDF AcroForm fields' data programmatically using VB.NET

  • Find a form field, or all fields in the PDF
  • Fill in field data by field name or position

How to fill-in AcroForm field value on PDF programmatically using VB.NET

  1. Download XDoc.PDF Form VB.NET library
  2. Install VB library to fill-in PDF AcroForm data programmatically
  3. Step by Step Tutorial










RasterEdge XDoc.PDF SDK package provides PDF field processing features for your VB.NET project. On this VB.NET tutorial, you will learn how to fill-in field data to PDF automatically in your VB.NET application. You could view the C# tutorial at How to add, fill-in PDF form field data using C#. Following VB.NET sample code can help you have a quick evaluation of it.

excel viewer asp.net c#, asp.net view image from database, how to edit pdf file using itextsharp in asp.net, asp.net c# view pdf, asp net add text to pdf, asp.net core pdf preview, view pdf in asp net mvc.





How to fill a field value in PDF AcroForm using VB.NET code?


The following steps and VB.NET example source code will show how to fill in values to all AcroForm fields by position in a PDF file using VB.NET.

  1. Use PDFFormHandler.GetFormFields() to get all form fields from an existing PDF file.
  2. For each field, you will get its page postion (X, Y values), and size (width and height)
  3. For each field, you will also use method PDFFormHandler.FillFormField() to fill in value to the form field by field's position


Dim inputFilePath As String = Program.RootPath + "\\" + "1_AF.pdf"
Dim outputFilePath As String = Program.RootPath + "\\" + "output.pdf"

Dim fields As List(Of BaseFormField) = PDFFormHandler.GetFormFields(inputFilePath)

Dim cnt As Integer = 0
For Each field As BaseFormField In fields

    Dim x As Single = field.Position.X + field.Size.Width / 2.0F
    Dim y As Single = field.Position.Y + field.Size.Height / 2.0F

    Console.WriteLine("Field Location: x = " + x + ", y = " + y)

    If TypeOf field Is AFCheckBox Then
        ' fill a CheckBox field, set state to ON
        Dim input As AFCheckBoxInput = New AFCheckBoxInput(True)
        PDFFormHandler.FillFormField(inputFilePath, 0, New PointF(x, y), input, outputFilePath + cnt.ToString() + ".pdf")
    ElseIf TypeOf field Is AFRadioButton Then
        ' fill a RadioButton field, set state to ON 
        Dim input As AFRadioButtonInput = New AFRadioButtonInput(True)
        PDFFormHandler.FillFormField(inputFilePath, 0, New PointF(x, y), input, outputFilePath + cnt.ToString() + ".pdf")
    ElseIf TypeOf field Is AFTextBox Then
        ' fill a TextBox field, change content to "Hello World"
        Dim input As AFTextBoxInput = New AFTextBoxInput("Hello World")
        PDFFormHandler.FillFormField(inputFilePath, 0, New PointF(x, y), input, outputFilePath + cnt.ToString() + ".pdf")
    ElseIf TypeOf field Is AFListBox Then
        ' fill a ListBox field, selete the 3rd item (with index value 2)
        Dim input As AFListBoxInput = New AFListBoxInput(New Integer() {2})
        PDFFormHandler.FillFormField(inputFilePath, 0, New PointF(x, y), input, outputFilePath + cnt.ToString() + ".pdf")
    ElseIf TypeOf field Is AFComboBox Then
        ' fill a BomboBox field, selete the 3rd item (with index value 2)
        Dim input As AFComboBoxInput = New AFComboBoxInput(2)
        PDFFormHandler.FillFormField(inputFilePath, 0, New PointF(x, y), input, outputFilePath + cnt.ToString() + ".pdf")
    End If

    cnt += 1
Next


The following steps and VB.NET example source code will show how to fill in values to all AcroForm fields by name in a PDF file using VB.NET.

  1. Use PDFFormHandler.GetFormFields() to get all form fields from an existing PDF file.
  2. For each field, you will get its name defined in the PDF document
  3. For each field, you will also use method PDFFormHandler.FillFormField() to fill in value to the form field by field's name


Dim inputFilePath As String = Program.RootPath + "\\" + "1_AF.pdf"
Dim outputFilePath As String = Program.RootPath + "\\" + "output.pdf"

Dim fields As List(Of BaseFormField) = PDFFormHandler.GetFormFields(inputFilePath)

Dim cnt As Integer = 0
For Each field As BaseFormField In fields

    If TypeOf field Is AFCheckBox Then
        ' fill a CheckBox field, set state to ON
        Dim input As AFCheckBoxInput = New AFCheckBoxInput(True)
        PDFFormHandler.FillFormField(inputFilePath, field.Name, input, outputFilePath + cnt.ToString() + ".pdf")
    ElseIf TypeOf field Is AFRadioButton Then
        ' fill a RadioButton field, set state to ON 
        Dim input As AFRadioButtonInput = New AFRadioButtonInput(True)
        PDFFormHandler.FillFormField(inputFilePath, field.Name, input, outputFilePath + cnt.ToString() + ".pdf")
    ElseIf TypeOf field Is AFTextBox Then
        ' fill a TextBox field, change content to "Hello World"
        Dim input As AFTextBoxInput = New AFTextBoxInput("Hello World!")
        PDFFormHandler.FillFormField(inputFilePath, field.Name, input, outputFilePath + cnt.ToString() + ".pdf")
    ElseIf TypeOf field Is AFListBox Then
        ' fill a ListBox field, selete the 3rd item (with index value 2)
        Dim input As AFListBoxInput = New AFListBoxInput(New Integer() {2})
        PDFFormHandler.FillFormField(inputFilePath, field.Name, input, outputFilePath + cnt.ToString() + ".pdf")
    ElseIf TypeOf field Is AFComboBox Then
        ' fill a BomboBox field, selete the 3rd item (with index value 2)
        Dim input As AFComboBoxInput = New AFComboBoxInput(2)
        PDFFormHandler.FillFormField(inputFilePath, field.Name, input, outputFilePath + cnt.ToString() + ".pdf")
    End If

    cnt += 1
Next