Spire.PDF allows importing FDF, XFDF files to PDF forms as well as exporting PDF forms data to FDF, XFDF files.
The below code examples illustrate how to implement the above features using Spire.PDF.
Importing FDF/ XFDF to PDF
To import FDF/XFDF file to PDF, we can use the ImportData method in the PdfFormWidget class:
using Spire.Pdf; using Spire.Pdf.Widget; namespace ImportingFDFOrXFDFtoPDF { class Program { static void Main(string []args) { //Load the PDF document PdfDocument document = new PdfDocument("Import.pdf"); //Load the existing forms PdfFormWidget loadedForm = document.Form as PdfFormWidget; //Import FDF to PDF loadedForm.ImportData("ImportFDF.fdf", DataFormat.Fdf); //Import XFDF to PDF //loadedForm.ImportData("ImportXFDF.xfdf", DataFormat.XFdf); //Save the document document.SaveToFile("Output.pdf"); //Close the document document.Close(); } } }
Exporting PDF Forms Data to FDF/XFDF
To export PDF forms data to FDF/XFDF file, we can use the ExportData method in the PdfFormWidget class:
using Spire.Pdf; using Spire.Pdf.Fields; using Spire.Pdf.Widget; namespace ExportingPDFFormsDatatoFDFAndXFDF { class Program { static void Main(string[] args) { // Load the PDF document PdfDocument document = new PdfDocument("Export.pdf"); //Load the existing forms PdfFormWidget loadedForm = document.Form as PdfFormWidget; //Export the first form to FDF PdfField field = loadedForm.FieldsWidget.List[0] as PdfField; loadedForm.ExportData("ExportFDF.fdf", DataFormat.Fdf, field.Name); //Export the first form to XFDF //loadedForm.ExportData("ExportXFDF.xfdf", DataFormat.XFdf, field.Name); //Close the document document.Close(); } } }