PDF: Extract field values from PDF interactive form
In This Topic
Here is C#/VB.NET code that demonstrates how to extract field values from PDF interactive form:
/// <summary>
/// Prints information about interactive form of PDF document.
/// </summary>
/// <param name="pdfFilename">The filename of PDF document.</param>
public static void ExtractFieldValuesFromPdfInteractiveForm(string pdfFilename)
{
// open PDF document
using (Vintasoft.Imaging.Pdf.PdfDocument document =
new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
{
// if PDF document has interactive form
if (document.InteractiveForm != null)
{
// get reference to the interactive form
Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm form =
document.InteractiveForm;
// get an array that contains all interactive form fields of PDF document
Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField[] formFields = form.GetTerminalFields();
// for each PDF interactive field
foreach (Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField field in formFields)
{
// output field name and field value
System.Console.WriteLine("Name={0}, Value={1}", field.FullyQualifiedName, field.FieldValue);
}
}
}
}
''' <summary>
''' Prints information about interactive form of PDF document.
''' </summary>
''' <param name="pdfFilename">The filename of PDF document.</param>
Public Shared Sub ExtractFieldValuesFromPdfInteractiveForm(pdfFilename As String)
' open PDF document
Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
' if PDF document has interactive form
If document.InteractiveForm IsNot Nothing Then
' get reference to the interactive form
Dim form As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm = document.InteractiveForm
' get an array that contains all interactive form fields of PDF document
Dim formFields As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField() = form.GetTerminalFields()
' for each PDF interactive field
For Each field As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField In formFields
' output field name and field value
System.Console.WriteLine("Name={0}, Value={1}", field.FullyQualifiedName, field.FieldValue)
Next
End If
End Using
End Sub