Extracting data from FDF (Forms Data Format)

Q: We need to manipulate an FDF stored in a database and then also
create PDFs to store in an imaging system.

Below is some VB.Net code that I use to read FDF documents. For some
reason I am not getting any values. Is there something I'm doing
wrong?

Imports System.Data.SqlClient
Imports PDFTRON
Imports PDFTRON.Common
Imports PDFTRON.SDF
Imports PDFTRON.FDF
Imports PDFTRON.PDF

Module Module1

    Sub Main()
        PDFNet.Initialize()

'Attach to DB and get rows
        Dim ConnectString =
"Server=xx.xxx.xx0.xx;Database=xxx;Uid=xxx;Pwd=xxx;"
        Dim Query = "Select * from xxx"
        Dim dbCon As New SqlConnection
        dbCon = New SqlConnection(ConnectString)
        Dim dbCom As New SqlCommand
        dbCom.Connection = dbCon
        dbCom.CommandType = CommandType.Text
        dbCom.CommandText = Query
        Try
            Dim dr As SqlDataReader
            dbCon.Open()
            dr = dbCom.ExecuteReader
            If dr.HasRows = True Then
                While dr.Read

'Load AppImage from DB to FDFDoc

                    Dim test As FDFDoc = New FDFDoc(dr("AppImage"),
5000)
        Console.WriteLine(test.GetPdfFileName)
                    Console.WriteLine(test.GetField("SigESign"))
                    Dim itr As FDFFieldIterator =
test.GetFieldIterator()
                    While Not itr.HasNext()
                        Console.WriteLine("Field name: {0:s}",
itr.Current().GetName())
                        Console.WriteLine("Field partial name: {0:s}",
itr.Current().GetPartialName())

Console.WriteLine("------------------------------")
                        itr.Next()
                    End While

                End While
            End If
            dbCon.Close()
        Catch ex As Exception
        End Try
        PDFNet.Terminate()
    End Sub
End Module
-----
A: Perhaps you should use 'While itr.HasNext()' instead of 'While Not
itr.HasNext()'

Using the following snippet:

PDFNet.Initialize();
try
{
  FDFDoc doc = new FDFDoc("c:\\fdftest.fdf");

  FDFFieldIterator itr;
  for(itr=doc.GetFieldIterator(); itr.HasNext(); itr.Next())
  {
    Console.WriteLine("Field name: {0:s}", itr.Current().GetName());
    Console.WriteLine("Field partial name: {0:s}",
itr.Current().GetPartialName());
    Console.WriteLine("------------------------------");
  }

  doc.Close();
  Console.WriteLine("Done.");
}
catch (PDFNetException e)
{
  Console.WriteLine(e.Message);
}

I get the following output:

Field name: CLUID
Field partial name: CLUID
------------------------------
Field name: PreApproved
Field partial name: PreApproved
------------------------------
Field name: Gender
Field partial name: Gender
------------------------------
Field name: MaritalStat
Field partial name: MaritalStat
------------------------------
Field name: NumDependents
Field partial name: NumDependents
------------------------------
...

Q: OK...that helped the field iterator...

So, how can I get the VALUE of a field?
-----
A: You can obtain a string value for FDF text fields as follows:

In C#
string value;
Obj v = field.GetValue();
if (v != null && v.IsString()) {
value = v.GetAsPDFText();
}

I guess the VB.NET version would look as follows:

Dim v as Obj = field.GetValue()
If Not v is Nothing And v.IsString() Then
  Dim value as string = v.GetAsPDFText()
End if