Q:
How do I fill PDF form using PDFNet SDK in VB.NET?
I am looking for someting very simple to use.
----
A:
You can use PDFNet SDK to programmatically fill-in PDF forms as
illustrated in
InteractiveForms (http://www.pdftron.com/net/
samplecode.html#InteractiveForms) and FDF (http://www.pdftron.com/net/
samplecode.html#FDF) sample projects. The following example sets the
new value for "MemberName":
Imports System
Imports pdftron
Imports pdftron.Common
Imports pdftron.SDF
Imports pdftron.PDF
Module Module1
Sub SetFieldValue(ByRef d As PDFDoc, ByVal name As String, ByVal
value As String)
Dim itr As FieldIterator = d.FieldFind(name)
If Not itr.Equals(d.FieldEnd()) Then
Dim field As Field = itr.Current()
' Console.WriteLine("Field search for {0} was
successful.", field.GetName())
field.SetValue(Obj.CreateString(value)) ' Set the value
Else
' Console.WriteLine("'{0}' not found.", value)
End If
End Sub
Sub Main()
PDFNet.Initialize()
PDFNet.SetResourcesPath("../../../../resources")
Try
Dim doc4 As PDFDoc = New PDFDoc("Test.pdf")
doc4.InitSecurityHandler()
SetFieldValue(doc4, "MemberName", "My Name")
doc4.RefreshFieldAppearances()
doc4.Save("Test2.pdf", 0)
doc4.Close()
Console.WriteLine("Done.")
Catch ex As PDFNetException
Console.WriteLine(ex.Message)
Catch ex As Exception
MsgBox(ex.Message)
End Try
PDFNet.Terminate()
End Sub
End Module
You can set the field value in C# along the same lines. For example:
FieldIterator itr = pdfdoc.FieldFind("name");
if (itr != pdfdoc.FieldEnd()) {
Field field = itr.Current();
field.SetValue(Obj.CreateString("John Doe"));
}