'--------------------------------------------------------------------------------------- ' Copyright (c) 2001-2008 by PDFTron Systems Inc. All Rights Reserved. ' Consult legal.txt regarding legal and license information. '--------------------------------------------------------------------------------------- Imports System Imports pdftron Imports pdftron.Common Imports pdftron.SDF Imports pdftron.FDF Imports pdftron.PDF Module Module1 '--------------------------------------------------------------------------------------- ' PDFNet includes a full support for FDF (Forms Data Format) and capability to merge/extract ' forms data (FDF) with/from PDF. This sample illustrates basic FDF merge/extract functionality ' available in PDFNet. '--------------------------------------------------------------------------------------- Sub Main() PDFNet.Initialize() PDFNet.SetResourcesPath("../../../../resources") ' Relative path to the folder containing test files. Dim input_path As String = "../../../TestFiles/" Dim output_path As String = "../../../TestFiles/Output/" ' Example 1) ' Iterate over all form fields in the document. Display all field names. Try Dim doc As PDFDoc = New PDFDoc(input_path + "form1.pdf") doc.InitSecurityHandler() Dim itr As FieldIterator = doc.GetFieldIterator() While itr.HasNext() Console.WriteLine("Field name: {0:s}", itr.Current().GetName()) Console.WriteLine("Field partial name: {0:s}", itr.Current().GetPartialName()) Console.Write("Field type: ") Dim type As Field.Type = itr.Current().GetType() If type = Field.Type.e_button Then Console.WriteLine("Button") ElseIf type = Field.Type.e_text Then Console.WriteLine("Text") ElseIf type = Field.Type.e_choice Then Console.WriteLine("Choice") ElseIf type = Field.Type.e_signature Then Console.WriteLine("Signature") End If Console.WriteLine("------------------------------") itr.Next() End While doc.Close() Console.WriteLine("Done.") Catch e As Exception Console.WriteLine("Exception caught:\n{0}", e) End Try ' Example 2) Merge data from FDF Try Console.WriteLine("Merge data from FDF") Dim doc As PDFDoc = New PDFDoc(input_path + "form1.pdf") doc.InitSecurityHandler() Dim fdf_doc As FDFDoc = New FDFDoc(input_path + "form1_data.fdf") doc.FDFMerge(fdf_doc) ' To use PDFNet form field appearance generation instead of relying on ' Acrobat, uncomment the following two lines: ' doc.RefreshFieldAppearances() ' doc.GetAcroForm().Put("NeedAppearances", Obj.CreateBool(false)) doc.Save(output_path + "form1_filled.pdf", SDF.SDFDoc.SaveOptions.e_linearized) doc.Close() Console.WriteLine("Done.") Catch e As Exception Console.WriteLine("Exception caught:\n{0}", e) End Try ' Example 3) Extract data to FDF Try Console.WriteLine("Extract data to FDF") Dim in_doc As PDFDoc = New PDFDoc(output_path + "form1_filled.pdf") in_doc.InitSecurityHandler() Dim doc As FDFDoc = in_doc.FDFExtract() doc.SetPdfFileName("../form1.pdf") doc.Save(output_path + "form1_filled_data.fdf") in_doc.Close() Console.WriteLine("Done.") Catch e As Exception Console.WriteLine("Exception caught:\n{0}", e) End Try ' Example 4) Read FDF files directly Try Dim doc As FDFDoc = New FDFDoc(output_path + "form1_filled_data.fdf") Dim itr As FDFFieldIterator = doc.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 Console.WriteLine("Done.") Catch e As Exception Console.WriteLine("Exception caught:\n{0}", e) End Try ' Example 5) Direct generation of FDF. Try Dim doc As FDFDoc = New FDFDoc ' Create new fields (i.e. key/value pairs). doc.FieldCreate("Company", Int(Field.Type.e_text), "PDFTron Systems") doc.FieldCreate("First Name", Int(Field.Type.e_text), "John") doc.FieldCreate("Last Name", Int(Field.Type.e_text), "Doe") ' ... ' doc.SetPdfFileName("mydoc.pdf"); doc.Save(output_path + "sample_output.fdf") Console.WriteLine("Done.") Catch e As Exception Console.WriteLine("Exception caught:\n{0}", e) End Try PDFNet.Terminate() End Sub End Module