AutoFiller Class
Represents a class to receive data from database or other datasource, fills them into the designed fields of the template pdf and at last generates new pdf file or stream. It has two template file input modes:input as a stream or a pdf file. It has four types of output modes:one merged stream, one merged file, many small streams, many small files. It can recieve literal data contained in a System.Data.DataTable.
Inheritance Hierarchy
SystemObject
  Aspose.Pdf.FacadesAutoFiller

Namespace: Aspose.Pdf.Facades
Assembly: Aspose.PDF (in Aspose.PDF.dll) Version: 20.3
Syntax
public sealed class AutoFiller : ISaveableFacade, 
	IFacade, IDisposable

The AutoFiller type exposes the following members.

Constructors
  NameDescription
Public methodAutoFiller
Initializes a new instance of the AutoFiller class
Properties
  NameDescription
Public propertyBasicFileName
Gets or sets the basic file name if many small files will be generated. The generated file will be like "BasicFileName0","BasicFileName1",... It works with another property GeneratingPathGeneratingPath.
Public propertyGeneratingPath
Gets or sets the Generating Path of the small pdf files if many small pdf files to be generated. It works with another property BasicFileNameBasicFileName. One of the four output modes.
Public propertyInputFileName Obsolete.
Gets or sets the input template file. One of two input modes.
Public propertyInputStream Obsolete.
Gets or sets the input template stream. One of two input modes.
Public propertyOutputFileName Obsolete.
Gets or sets the one big merged output file. One of the four output modes.
Public propertyOutputStream Obsolete.
Gets or sets the OutputStream. One of four output modes. Its classical use case is Response.OutputStream. Please refer to the online demo.
Public propertyOutputStreams
Gets or sets the many Output Streams. One of four output modes.
Public propertyUnFlattenFields
Sets the fields which will not be flattened. If this property is not set, all the fields will be flattened.
Methods
  NameDescription
Public methodBindPdf(Stream)
Binds a Pdf file.
Public methodBindPdf(String)
Binds a Pdf file.
Public methodBindPdf(Document)
Binds a Pdf document.
Public methodClose
Closes the object and output streams.
Public methodDispose
Closes the object and output streams.
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodImportDataTable
Imports data of DataTable type. Every column's name of the dataTable must be the same as one field name of the template pdf in case sensitive.
Public methodSave Obsolete.
Saves all the pdfs.
Public methodSave(Stream)
Saves all the pdfs.
Public methodSave(String)
Saves all the pdfs.
Public methodToString (Inherited from Object.)
Examples
   [C#]
//Note: mail.pdf is a template pdf which has seven text fields. NorthWind.mdb is the microsoft access db.
////Common part: Get the data from the database NorthWind.mdb fill it into the DataTable.

   OleDbCommand mQueryCommand;
   OleDbDataAdapter mDbDataAdapter;
   OleDbConnection mDbConnection;

   //Construct the data table.
   DataTable mDataTable = new DataTable("MailMerge");
   DataColumnCollection columns = mDataTable.Columns;
   columns.Add("CompanyName",typeof(string));
   columns.Add("ContactName",typeof(string));
   columns.Add("Address",typeof(string));
   columns.Add("PostalCode",typeof(string));
   columns.Add("City",typeof(string));
   columns.Add("Country",typeof(string));
   columns.Add("Heading",typeof(string));


   //Connect to the database source and query the data.
   mDbConnection = new OleDbConnection();
   mDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + 
   DbPath + "NorthWind.mdb";
   mQueryCommand = new OleDbCommand();
   mQueryCommand.Connection = mDbConnection;
   mDbConnection.Open();


   mQueryCommand.CommandText = "select CompanyName, ContactName, Address, PostalCode, City, Country from Customers;";
   mDbDataAdapter = new OleDbDataAdapter(mQueryCommand);

   mDbDataAdapter.Fill(mDataTable);

   for (int i = 0; i<mDataTable.Rows.Count;i++)
   {
       mDataTable.Rows[i][mDataTable.Columns.Count - 1] = "Dear " + mDataTable.Rows[i][0].ToString() + ",";
       System.Console.WriteLine("postalCode:" + mDataTable.Rows[i][3].ToString());
       System.Console.WriteLine("Heading:" + mDataTable.Rows[i][mDataTable.Columns.Count - 1].ToString());
   }

   mDbDataAdapter.Dispose();
   mDbConnection.Close();
   ////End of Common part.

   ////case one:
   ////Input template pdf is a pdf file and output is a big merged stream.        

   AutoFiller autoFiller = new AutoFiller();

   autoFiller.InputFileName = "mail.pdf";
   autoFiller.OutputStream = Response.OutputStream;

   autoFiller.ImportDataTable(mDataTable);
   autoFiller.Save();

   ////case two:
   ////Input template pdf is a pdf file and output is a lot of small files.
   AutoFiller autoFiller = new AutoFiller();

   autoFiller.InputFileName = "mail.pdf";
   autoFiller.GeneratingPath = ".\\";
   autoFiller.BasicFileName = "outputFile";

   autoFiller.ImportDataTable(mDataTable);
   autoFiller.Save();

   [Visual Basic]
   'Note: mail.pdf is a template pdf which has seven text fields. NorthWind.mdb is the microsoft access db.
   'Common part: Get the data from the database NorthWind.mdb fill it into the DataTable. 
   mQueryCommand As OleDbCommand = Nothing
   mDbDataAdapter As OleDbDataAdapter = Nothing
   mDbConnection As OleDbConnection = Nothing

   mDataTable As DataTable = Nothing

   mPath As String = Nothing
   mTemplatePdf As String = Nothing

   'Construct the data table.
   mDataTable = New DataTable("MailMerge")
   Dim columns As DataColumnCollection = mDataTable.Columns
   'Create columns for the datatable. 
   'Every column's  name should be the same as one field's name of the templatePdf.
   columns.Add("CompanyName", Type.GetType("System.String"))

   columns.Add("ContactName", Type.GetType("System.String"))
   columns.Add("Address", Type.GetType("System.String"))
   columns.Add("PostalCode", Type.GetType("System.String"))
   columns.Add("City", Type.GetType("System.String"))
   columns.Add("Country", Type.GetType("System.String"))
   columns.Add("Heading", Type.GetType("System.String"))


   'Connect to the database source and query the data.
   mDbConnection = New OleDbConnection
   mDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DbPath + "NorthWind.mdb"
   mQueryCommand = New OleDbCommand
   mQueryCommand.Connection = mDbConnection
   mDbConnection.Open()

   'Query the data and insert into the datatable.
   mQueryCommand.CommandText = "select CompanyName, ContactName, Address, PostalCode, City, Country from Customers;"
   mDbDataAdapter = New OleDbDataAdapter(mQueryCommand)
   mDbDataAdapter.Fill(mDataTable)

   'Construct the last column  of the Datatable.
   Dim i As Integer
   For i = 0 To mDataTable.Rows.Count - 1 Step i + 1
       mDataTable.Rows(i)(mDataTable.Columns.Count - 1) = "Dear " + mDataTable.Rows(i)(0).ToString() + ","
       System.Console.WriteLine("postalCode:" + mDataTable.Rows(i)(3).ToString())
       System.Console.WriteLine("Heading:" + mDataTable.Rows(i)(mDataTable.Columns.Count - 1).ToString())
   Next

   mDbDataAdapter.Dispose()
   mDbConnection.Close()
   'End of Common part.

   'case one:
   'Input template pdf is a pdf file and output is a big merged stream.
   Dim autoFiller As AutoFiller = New AutoFiller

   autoFiller.InputFileName = "mail.pdf"
   autoFiller.OutputStream = Response.OutputStream

   autoFiller.ImportDataTable(mDataTable)
   autoFiller.Save()

   'case two:
   'Input template pdf is a pdf file and output is a lot of small files.
   Dim autoFiller As AutoFiller = New AutoFiller

   autoFiller.InputFileName = "mail.pdf"
   autoFiller.GeneratingPath = ".\";
   autoFiller.BasicFileName = "outputFile"

   autoFiller.ImportDataTable(mDataTable)
   autoFiller.Save()
See Also