Import FDF into PDF

PDF forms
7/8/2014

Import FDF (Form Data Format) into a PDF form and save the PDF with imported data.

The data in PDF forms can be exported as a FDF file, which allows you to quickly insert it into databases among other uses. In this code sample we will show how you can easily import an FDF file and populate the form fields in a PDF.

C# code sample

1 //import PDF document where the fields will be filled 2 using (FileStream fileIn = new FileStream(@"..\..\..\inputDocuments\fw4.pdf", FileMode.Open, FileAccess.Read)) 3 { 4 Document document = new Document(fileIn); 5 6 //import form data, which automatically fills the fields in fw4.pdf 7 using (FileStream fdfFile = new FileStream(@"..\..\fw4.fdf", FileMode.Open, FileAccess.Read)) 8 { 9 FdfFormData fdfData = new FdfFormData(fdfFile); 10 document.Import(fdfData); 11 } 12 13 //export the filled out pdf to disk 14 using (FileStream fileOut = new FileStream(@"..\..\fw4_afterimport.pdf", FileMode.Create, FileAccess.Write)) 15 { 16 document.Write(fileOut); 17 } 18 }

VB.NET code sample

1 Using fileIn As New FileStream("..\..\..\inputDocuments\fw4.pdf", FileMode.Open, FileAccess.Read) 2 Dim document As New Document(fileIn) 3 4 Using fdfFile As New FileStream("..\..\fw4.fdf", FileMode.Open, FileAccess.Read) 5 Dim fdfData As New FdfFormData(fdfFile) 6 document.Import(fdfData) 7 End Using 8 9 Using fileOut As New FileStream("..\..\fw4_afterimport.pdf", FileMode.Create, FileAccess.Write) 10 document.Write(fileOut) 11 End Using 12 End Using 13 }