Document Solutions for PDF
Features / Forms / Import and Export Forms Data
In This Topic
    Import and Export Forms Data
    In This Topic

    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.

    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 method of GcPdfDocument class, while the forms data can be exported to FDF by calling the ExportFormDataToFDF method of GcPdfDocument class.

    The following code snippet illustrates how to import from FDF and export to FDF.

    C#
    Copy Code
    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");
    
    }
    
    Back to Top

    Import or Export Forms Data from XFDF

    The forms data can be imported from XFDF by calling the ImportFormDataFromXFDF method of GcPdfDocument class, while the forms data can be exported to XFDF by calling the ExportFormDataToXFDF method of GcPdfDocument class.

    The following code snippet illustrates how to import from XFDF and export to XFDF.

    C#
    Copy Code
    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"); 
    }
    
    Back to Top

    Import or Export Forms Data from XML

    The forms data can be imported from XML by calling the ImportFormDataFromXML method of GcPdfDocument class, while the forms data can be exported to XML by calling the ExportFormDataToXML method of GcPdfDocument class.

    The following code snippet illustrates how to import from XML and export to XML.

    C#
    Copy Code
    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"); 
    }
    
    Back to Top