# Import and Export Forms Data

DsPdf allows you to import and export PDF forms data in FDF, XFDF and XML file formats.

## Content

PDFs contain forms, which after being filled can be transferred over the web as forms data. The common formats used to transfer forms data over the web are FDF, XFDF and XML. These files are convenient to transfer since they are much smaller in size than the original PDF form file. The DsPdf library supports the import and export of PDF forms data in FDF, XFDF and XML file formats.

* **FDF:** An FDF file stands for Forms Data Format file and stores the values of form fields in a key/value pair fashion.
* **XFDF:** An XFDF file is an encoded XML version of FDF and stores the value of form fields in a hierarchical manner using XML tags.
* **XML:** An XML file is a plain text format, and majority of the applications prefer this format for storing and sharing data.

Note that the forms data can also be imported or exported from or to streams (in-memory objects) files.

## Import or Export Forms Data from FDF

The forms data can be imported from FDF by calling the [ImportFormDataFromFDF](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfDocument.ImportFormDataFromFDF.html) method of [GcPdfDocument](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfDocument.html) class, while the forms data can be exported to FDF by calling the [ExportFormDataToFDF](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfDocument.ExportFormDataToFDF.html) method of GcPdfDocument class.
The following code snippet illustrates how to import from FDF and export to FDF.

```csharp
public void ImportDataFromFDF()
{
    var doc = new GcPdfDocument();
    //Load the document  
    doc.Load(new FileStream(Path.Combine("Pdf_BlankForm.pdf"), FileMode.Open, FileAccess.Read));
    //Open the FDF file
    FileStream stream = new FileStream(Path.Combine("FDF_Data.fdf"), FileMode.Open, FileAccess.Read); 
    doc.ImportFormDataFromFDF(stream); //Import the form data        
    doc.Save("PdfForm_FDF.pdf"); //Save the document
}
public void ExportDataToFDF()
{
    var doc = new GcPdfDocument();
    //Load the document 
    doc.Load(new FileStream(Path.Combine("Pdf_FilledForm.pdf"), FileMode.Open, FileAccess.Read));
    //Export the form data to a stream   
    MemoryStream stream = new MemoryStream();
    doc.ExportFormDataToFDF(stream);

    //Alternatively, we can even export to a file of appropriate format
    //Export the form data to a FDF file
    //doc.ExportFormDataToFDF("FDF_Data.fdf");

}
```

## Import or Export Forms Data from XFDF

The forms data can be imported from XFDF by calling the [ImportFormDataFromXFDF](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfDocument.ImportFormDataFromXFDF.html) method of GcPdfDocument class, while the forms data can be exported to XFDF by calling the [ExportFormDataToXFDF](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfDocument.ExportFormDataToXFDF.html) method of GcPdfDocument class.
The following code snippet illustrates how to import from XFDF and export to XFDF.

```csharp
public void ImportDataFromXFDF()
    {
        var doc = new GcPdfDocument();
        //Load the document 
        doc.Load(new FileStream(Path.Combine("Pdf_BlankForm.pdf"), FileMode.Open, FileAccess.Read));
        //Open the XFDF file
        FileStream stream = new FileStream(Path.Combine("XFDF_Data.xfdf"), FileMode.Open, FileAccess.Read);
        //Import the form data   
        doc.ImportFormDataFromXFDF(stream);
        //Save the document
        doc.Save("PdfForm_XFDF.pdf"); 
    }
    public void ExportDataToXFDF()
    {
        var doc = new GcPdfDocument();
        //Load the document
        doc.Load(new FileStream(Path.Combine("Pdf_FilledForm.pdf"), FileMode.Open, FileAccess.Read)); 

        MemoryStream stream = new MemoryStream();
        //Export the form data to a stream    
        doc.ExportFormDataToXFDF(stream);          

        //Alternatively, we can even export to a file of appropriate format
        //Export the form data to a XFDF file
        //doc.ExportFormDataToXFDF("XFDF_Data.xfdf"); 
}
```

## Import or Export Forms Data from XML

The forms data can be imported from XML by calling the [ImportFormDataFromXML](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfDocument.ImportFormDataFromXML.html) method of GcPdfDocument class, while the forms data can be exported to XML by calling the [ExportFormDataToXML](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfDocument.ExportFormDataToXML.html) method of GcPdfDocument class.
The following code snippet illustrates how to import from XML and export to XML.

```csharp
public void ImportDataFromXML()
{
    var doc = new GcPdfDocument();
    //Load the document 
    doc.Load(new FileStream(Path.Combine("Pdf_BlankForm.pdf"), FileMode.Open, FileAccess.Read));
    //Open the XML file
    FileStream stream = new FileStream(Path.Combine("XML_Data.xml"), FileMode.Open, FileAccess.Read);
    //Import the form data 
    doc.ImportFormDataFromXML(stream);
    //Save the document
    doc.Save("PdfForm_XML.pdf"); 
}
public void ExportDataToXML()
{
    var doc = new GcPdfDocument();
    //Load the document
    doc.Load(new FileStream(Path.Combine("Pdf_FilledForm.pdf"), FileMode.Open, FileAccess.Read)); 

    MemoryStream stream = new MemoryStream();
    //Export the form data to a stream   
    doc.ExportFormDataToXML(stream);

    //Alternatively, we can even export to a file of appropriate format
    //Export the form data to an XML file
    //doc.ExportFormDataToXML("XML_Data.xml"); 
}
```