com.aspose.pdf.facades

Class AutoFiller

  • All Implemented Interfaces:
    com.aspose.ms.System.IDisposable, IFacade, ISaveableFacade, Closeable, AutoCloseable


    public final class AutoFiller
    extends Object
    implements ISaveableFacade, Closeable

    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.


      //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.setConnectionString ( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + 
            DbPath + "NorthWind.mdb");
            mQueryCommand = new OleDbCommand();
            mQueryCommand.setConnection ( mDbConnection);
            mDbConnection.open();
            mQueryCommand.setCommandText ( "select CompanyName, ContactName, Address, PostalCode, City, Country from Customers;");
            mDbDataAdapter = new OleDbDataAdapter(mQueryCommand);
                            
            mDbDataAdapter.fill(mDataTable);
            
            for (int i = 0; i<mDataTable.getRows().size();i++)
            {
                    mDataTable.getRows()[i][mDataTable.getColumns().size() - 1] = "Dear " + mDataTable.Rows[i][0].ToString() + ",";
                    System.out.println("postalCode:" + mDataTable.getRows()[i][3].toString());
                    System.out.println("Heading:" + mDataTable.getRows()[i][mDataTable.getColumns().Size() - 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.setInputFileName ( "mail.pdf");
            autoFiller.setOutputStream ( Response.getOutputStream());
            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.setInputFileName ( "mail.pdf"0;
            autoFiller.setGeneratingPath ( ".\\");
            autoFiller.setBasicFileName ( "outputFile");
            autoFiller.importDataTable(mDataTable);
            autoFiller.save();
     
    • Constructor Detail

      • AutoFiller

        public AutoFiller()
    • Method Detail

      • setUnFlattenFields

        public void setUnFlattenFields(String[] value)

        Sets the fields which will not be flattened. If this property is not set, all the fields will be flattened.

        Parameters:
        value - array of String value
      • getOutputStream

        @Deprecated
        public OutputStream getOutputStream()
        Deprecated. 

        Gets the OutputStream. One of four output modes. Its classical use case is Response.OutputStream. Please refer to the online demo.

        This method is Deprecated.
        Returns:
        the output stream
      • setOutputStream

        @Deprecated
        public void setOutputStream(OutputStream value)
        Deprecated. 

        Sets the OutputStream. One of four output modes. Its classical use case is Response.OutputStream. Please refer to the online demo.

        This method is Deprecated.
        Parameters:
        value - the output stream
      • getInputStream

        @Deprecated
        public InputStream getInputStream()
        Deprecated. 

        Gets the input template stream. One of two input modes.

        Returns:
        InputStream element
      • setInputStream

        @Deprecated
        public void setInputStream(InputStream value)
        Deprecated. 

        Sets the input template stream. One of two input modes.

        Parameters:
        value - InputStream element
      • getInputFileName

        @Deprecated
        public String getInputFileName()
        Deprecated. 

        Gets the input template file. One of two input modes.

        Returns:
        String value
      • setInputFileName

        @Deprecated
        public void setInputFileName(String value)
        Deprecated. 

        Sets the input template file. One of two input modes.

        Parameters:
        value - String value
      • getOutputFileName

        @Deprecated
        public String getOutputFileName()
        Deprecated. 

        Gets the one big merged output file. One of the four output modes.

        Returns:
        String value
      • setOutputFileName

        @Deprecated
        public void setOutputFileName(String value)
        Deprecated. 

        Sets the one big merged output file. One of the four output modes.

        Parameters:
        value - String value
      • getGeneratingPath

        public String getGeneratingPath()

        Gets the Generating Path of the small pdf files if many small pdf files to be generated. It works with another property BasicFileName BasicFileName. One of the four output modes.

        Returns:
        String value
      • setGeneratingPath

        public void setGeneratingPath(String value)

        Sets the Generating Path of the small pdf files if many small pdf files to be generated. It works with another property BasicFileName BasicFileName. One of the four output modes.

        Parameters:
        value - String value
      • getBasicFileName

        public String getBasicFileName()

        Gets 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.

        Returns:
        String value
      • setBasicFileName

        public void setBasicFileName(String value)

        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.

        Parameters:
        value - String value
      • save

        @Deprecated
        public void save()
        Deprecated. 

        Saves all the pdfs.

      • save

        public void save(String destFile)

        Saves all the pdfs.

        Specified by:
        save in interface ISaveableFacade
        Parameters:
        destFile - Output file name.
      • save

        public void save(OutputStream destStream)

        Saves all the pdfs.

        Specified by:
        save in interface ISaveableFacade
        Parameters:
        destStream - Output stream.
      • bindPdf

        public void bindPdf(String srcFile)

        Binds a Pdf file.

        Specified by:
        bindPdf in interface IFacade
        Parameters:
        srcFile - Pdf file name.
      • bindPdf

        public void bindPdf(InputStream srcStream)

        Binds a Pdf file.

        Specified by:
        bindPdf in interface IFacade
        Parameters:
        srcStream - Pdf file stream.
      • bindPdf

        public void bindPdf(IDocument srcDoc)

        Binds a Pdf document.

        Specified by:
        bindPdf in interface IFacade
        Parameters:
        srcDoc - Pdf document.
      • dispose

        @Deprecated
        public void dispose()
        Deprecated. 

        Closes the object and output streams.

        This method is obsolete, use close() instead.
        Specified by:
        dispose in interface com.aspose.ms.System.IDisposable