To merge and analyze the data in the fields of multiple pdfs filled by the customers is a common application. FormDataConverter can help you collect these data and import them into the database. Conversely, FormDataConverter also can export the data in the database into the files with many fields. Currently, the supported file types are FDF,XML,XFDF,PDF, the supported database are OLEDB, OdbcDB.
To use this class, just follow these steps:
- Create a table in the database if the table doesn't exist.
- Define the FormDataConverter.Table to map the fields' names to the table's columns' names.
- Call the API to export or import data.
Code Snippet
[C#]
//Import data into the database
FormDataConverter converter = new FormDataConverter();
//Define the DataTable.
DataTable mDataTable = new DataTable();
mDataTable.TableName = "TestConvertor";
DataColumnCollection columns = mDataTable.Columns;
columns.Add("Company",typeof(string));
columns.Add("Address.1",typeof(string));
columns["Address.1"].Caption = "Address1";
columns.Add("Address.2",typeof(string));
columns["Address.2"].Caption = "Address2";
converter.Table = mDataTable;
DataType sourceType = DataType.XML;
FileStream[] sourceStreams = new FileStream[2];
sourceStreams[0] = new FileStream("Convertor.xml", FileMode.Open);
sourceStreams[1] = new FileStream("Convertor2.xml", FileMode.Open);
converter.ConvertToDataTable(sourceStreams, sourceType);
string TestPath = @".\UnitTest\form\FormFiller\";
string connectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + TestPath + "test.mdb";
DataType dbType = DataType.OLEDB;
converter.ImportIntoDataBase(connectString, dbType);
//Export data from the database
converter = new FormDataConverter();
converter.Table = mDataTable;
DataType destType = DataType.XML;
dbType = DataType.OLEDB;
TestPath = @".\UnitTest\form\FormFiller\";
connectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
TestPath + "test.mdb";
//Export data from the databse into the FormDataConverter.Table
converter.ExportFromDataBase(connectString, dbType);
FileStream[] destStreams = new FileStream[converter.Table.Rows.Count];
destStreams[0] = new FileStream("ConvertorNew.xml", FileMode.Create);
destStreams[1] = new FileStream("ConvertorNew2.xml", FileMode.Create);
converter.ConverToStreams(destStreams, destType);
[Visual Basic]
'Import data into the database
Dim converter As FormDataConverter = New FormDataConverter()
'Define the DataTable.
Dim mDataTable As DataTable = New DataTable()
mDataTable.TableName = "TestConvertor"
Dim columns As DataColumnCollection = mDataTable.Columns
columns.Add("Company",Type.GetType(String))
columns.Add("Address.1",Type.GetType(String))
columns("Address.1").Caption = "Address1"
columns.Add("Address.2",Type.GetType(String))
columns("Address.2").Caption = "Address2"
converter.Table = mDataTable
Dim sourceType As DataType = DataType.XML
Dim sourceStreams() As FileStream = New FileStream(2) {}
sourceStreams(0) = New FileStream("Convertor.xml", FileMode.Open)
sourceStreams(1) = New FileStream("Convertor2.xml", FileMode.Open)
converter.ConvertToDataTable(sourceStreams, sourceType)
Dim TestPath As String = ".\UnitTest\form\FormFiller\"
String connectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
TestPath + "test.mdb"
Dim dbType As DataType = DataType.OLEDB
converter.ImportIntoDataBase(connectString, dbType)
'Export data from the database
converter = New FormDataConverter()
converter.Table = mDataTable
Dim destType As DataType = DataType.XML
dbType = DataType.OLEDB
TestPath = ".\UnitTest\form\FormFiller\"
connectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + TestPath + "test.mdb"
'Export data from the databse into the FormDataConverter.Table
converter.ExportFromDataBase(connectString, dbType)
Dim destStreams() As FileStream = New FileStream(converter.Table.Rows.Count) {}
destStreams(0) = New FileStream("ConvertorNew.xml", FileMode.Create)
destStreams(1) = New FileStream("ConvertorNew2.xml", FileMode.Create)
converter.ConverToStreams(destStreams, destType)