Products
PDFKit.NET 4.0
Created
7/8/2014
Tags
PDF forms

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.

//import PDF document where the fields will be filled
using (FileStream fileIn = new FileStream(@"..\..\..\inputDocuments\fw4.pdf", FileMode.Open, FileAccess.Read))
{
    Document document = new Document(fileIn);

    //import form data, which automatically fills the fields in fw4.pdf
    using (FileStream fdfFile = new FileStream(@"..\..\fw4.fdf", FileMode.Open, FileAccess.Read))
    {
        FdfFormData fdfData = new FdfFormData(fdfFile);
        document.Import(fdfData);
    }

    //export the filled out pdf to disk
    using (FileStream fileOut = new FileStream(@"..\..\fw4_afterimport.pdf", FileMode.Create, FileAccess.Write))
    {
        document.Write(fileOut);
    }
}
Using fileIn As New FileStream("..\..\..\inputDocuments\fw4.pdf", FileMode.Open, FileAccess.Read)
            Dim document As New Document(fileIn)

            Using fdfFile As New FileStream("..\..\fw4.fdf", FileMode.Open, FileAccess.Read)
                Dim fdfData As New FdfFormData(fdfFile)
                document.Import(fdfData)
            End Using

            Using fileOut As New FileStream("..\..\fw4_afterimport.pdf", FileMode.Create, FileAccess.Write)
                document.Write(fileOut)
            End Using
End Using