PDF forms filling automation process

it’s not working. please check this there any incorrect. there is not arguments
Imports System.IO
Imports iText.Kernel.Pdf
Imports iText.Forms
Imports iText.Forms.Fields

Public Class FillPdfForm
Public Sub FillForm()
’ Replace these paths with your actual PDF file paths
Dim src As String = “D:\Downloads\Electronic Check Copy Req.pdf”
Dim dest As String = “D:\Downloads\Electronic Check Copy Req.pdf”

    Using pdf As New PdfDocument(New PdfReader(src), New PdfWriter(dest))
        Dim form = PdfAcroForm.GetAcroForm(pdf, True)

        ' Replace field names and values as per your requirement
        form.GetField("name").SetValue("James Bond")
        form.GetField("language").SetValue("English")
        form.GetField("experience1").SetValue("Off")
        form.GetField("experience2").SetValue("Yes")
        form.GetField("experience3").SetValue("Yes")
        form.GetField("shift").SetValue("Any")
        form.GetField("info").SetValue("I was 38 years old when I became an MI6 agent.")

        ' Optional: Flatten the form fields to make them read-only
        ' form.FlattenFields()
    End Using

    Console.WriteLine("PDF form filled successfully!")
End Sub

End Class

Hi @Sayed_Tabrez2

Try this:

Imports System.IO
Imports iText.Kernel.Pdf
Imports iText.Forms
Imports iText.Forms.Fields

Public Class FillPdfForm
    Public Sub FillForm()
        ' Replace these paths with your actual PDF file paths
        Dim src As String = "D:\Downloads\Electronic Check Copy Req.pdf"
        Dim dest As String = "D:\Downloads\FilledForm.pdf"

        Using pdf As New PdfDocument(New PdfReader(src), New PdfWriter(dest))
            Dim form = PdfAcroForm.GetAcroForm(pdf, True)

            ' Replace field names and values as per your requirement
            form.GetField("name").SetValue("James Bond")
            form.GetField("language").SetValue("English")
            form.GetField("experience1").SetValue("Off")
            form.GetField("experience2").SetValue("Yes")
            form.GetField("experience3").SetValue("Yes")
            form.GetField("shift").SetValue("Any")
            form.GetField("info").SetValue("I was 38 years old when I became an MI6 agent.")

            ' Optional: Flatten the form fields to make them read-only
            ' form.FlattenFields()
        End Using

        Console.WriteLine("PDF form filled successfully!")
    End Sub
End Class

Hope it helps!!

1 Like

its not working
Using pdf As New PdfDocument(New PdfReader(src), New PdfWriter(dest)) this thing need to define

Hi @Sayed_Tabrez2

If possible can you the pdf.

Regards

can’t able to share through attachment. because I’m new user

@Sayed_Tabrez

I will try and get back to you.

Regards

1 Like

Hi

any update?

Regards