Export FDF from PDF form
Export FDF from PDF form
This code sample helps to exports FDF from PDF.
With PDFs it is possible to export the filled-in form data seperately from the PDF document itself. This format is called FDF (Form Data Format) and can be used for quick data processing and storage in databases. In this code sample you can see how you can create it from a PDF document.
using ( FileStream pdfFile = new FileStream( @"..\..\..\inputDocuments\fw4.pdf", FileMode.Open, FileAccess.Read ) )
{
Document document = new Document( pdfFile );
TextField firstName = document.Fields[ "f1_09(0)" ] as TextField;
firstName.Value = "Chris";
TextField lastName = document.Fields[ "f1_10(0)" ] as TextField;
lastName.Value = "Sharp";
FdfFormData fdf = document.Export(SubmitFormat.Fdf, false) as FdfFormData;
fdf.Path = "fw4.pdf";
using ( FileStream fdfFile = new FileStream( @"..\..\fw4.fdf", FileMode.Create, FileAccess.Write ) )
{
fdf.Write( fdfFile );
}
}
Using pdfFile As New FileStream("..\..\..\inputDocuments\fw4.pdf", FileMode.Open, FileAccess.Read)
Dim document As New Document(pdfFile)
Dim firstName As TextField = TryCast(document.Fields("f1_09(0)"), TextField)
firstName.Value = "Chris"
Dim lastName As TextField = TryCast(document.Fields("f1_10(0)"), TextField)
lastName.Value = "Sharp"
Dim fdf As FdfFormData = TryCast(document.Export(SubmitFormat.Fdf, False), FdfFormData)
fdf.Path = "fw4.pdf"
Using fdfFile As New FileStream("..\..\fw4.fdf", FileMode.Create, FileAccess.Write)
fdf.Write(fdfFile)
End Using
End Using