Home  Products  Purchase  Downloads  Demos  Forums  Blogs  Ticket  Wiki  API  Corporate

com.aspose.pdf.kit
Class AutoFiller

java.lang.Object
  extended bycom.aspose.pdf.kit.AutoFiller

public class AutoFiller
extends java.lang.Object

Represents class to recieve data from database or other datasource (eg. XML), fills them into the pre-designed fields of the template pdf and at last generate new pdf file(s) or stream(s). 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 and many small files. It can be used like this:

 CASE 1: input file, output pdf file(s):
     AutoFiller autoFiller = new AutoFiller(columnName, dataSource);
     //uncomment the next line will produce a single big pdf file.
     //autoFiller.setGenMultiPdfs(false);
     //set input and output file names like this:
     autoFiller.setBasicPath("./examples/samplePdfs/");
     autoFiller.setBasicFileName("output");
     autoFiller.setInputFile("autoFillerTest.pdf");
     //set a field which will keep unflattened like this:
     autoFiller.unFlatten("Name");
     //fill data into the template like this:
     autoFiller.importData( );
     //close the opened files and streams like this:
     autoFiller.close();

 

CASE 2: input file, output multiple small pdf output streams: AutoFiller autoFiller = new AutoFiller(columnName, dataSource); autoFiller.setBasicPath("./examples/samplePdfs/"); autoFiller.setInputFile("autoFillerTest.pdf"); //initialize the output stream set like this: ByteArrayOutputStream[] outputs = new ByteArrayOutputStream[filesCount]; for (int i = 0; i < filesCount; i++) outputs[i] = new ByteArrayOutputStream(); //output streams will be put into outputs after close() autoFiller.setOutStreams(outputs); autoFiller.unFlatten("Name"); autoFiller.importData(); autoFiller.close();

CASE 3: here we test the methods, produce output stream(s). AutoFiller autoFiller = new AutoFiller(columnName, dataSource); autoFiller.setGenMultiPdfs(false); autoFiller.setBasicPath("./examples/samplePdfs/"); autoFiller.setInputFile("autoFillerTest.pdf"); FileOutputStream fileoutput = new FileOutputStream("test.pdf"); BufferedOutputStream output = new BufferedOutputStream(fileoutput); autoFiller.setOutStream(output); autoFiller.unFlatten("Name"); autoFiller.importData(); autoFiller.close(); output.close(); fileoutput.close();


Constructor Summary
AutoFiller(java.util.Vector fields, java.util.Vector dataSource)
          Represents a constructor of the AutoFiller object, two vector parameters should be provided.
 
Method Summary
 void close()
          Close all streams to release related resources and write contents into outputs.
 java.lang.String getBasicPath()
          The getter of the basicPath member.
 java.io.OutputStream[] getOutputStreams()
          The getter of the output streams.
 void importData()
          Automatically fill data into pre-defined template file and get file(s) output.
 boolean isGenMultiPdfs()
          The getter of the genMultiPdfs member.
 void setBasicFileName(java.lang.String basicFileName)
          The setter of the basicFileName member.
 void setBasicPath(java.lang.String basicPath)
          The setter of the basicPath member.
 void setGenMultiPdfs(boolean genMultiPdfs)
          The setter of the genMultiPdfs member.
 void setInputFile(java.lang.String inputFile)
          The setter of the inputFile member.
 void setInputStream(java.io.InputStream inputStream)
          The setter of the inputStream member.
 void setOutStream(java.io.OutputStream outStream)
          The setter of the desStream member.
 void setOutStreams(java.io.OutputStream[] outputStreams)
          The setter of the outputStreams member.
 void unFlatten(java.lang.String fieldName)
          Specifies a field which will not be flattened in all the output file(s) or stream(s).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutoFiller

public AutoFiller(java.util.Vector fields,
                  java.util.Vector dataSource)
Represents a constructor of the AutoFiller object, two vector parameters should be provided.

Parameters:
fields - A string object vector, containing the fields name of every field to be filled.
dataSource - A composite vector object consist of serveral other vector objects, each one contains a set of string values.
Method Detail

importData

public void importData()
                throws java.lang.Exception
Automatically fill data into pre-defined template file and get file(s) output.

Throws:
java.lang.Exception - On error.

unFlatten

public void unFlatten(java.lang.String fieldName)
Specifies a field which will not be flattened in all the output file(s) or stream(s).

Parameters:
fieldName - The fully qualified field name.

close

public void close()
           throws java.lang.Exception
Close all streams to release related resources and write contents into outputs.

Throws:
java.lang.Exception - On error.

isGenMultiPdfs

public boolean isGenMultiPdfs()
The getter of the genMultiPdfs member.

Returns:
The value of the genMultiPdfs member, default value is true.

setGenMultiPdfs

public void setGenMultiPdfs(boolean genMultiPdfs)
The setter of the genMultiPdfs member.

Parameters:
genMultiPdfs - If need multiple outputs, set true; otherwise set false.

getBasicPath

public java.lang.String getBasicPath()
The getter of the basicPath member.

Returns:
The value of basicPath member, default value is ".".

setBasicPath

public void setBasicPath(java.lang.String basicPath)
The setter of the basicPath member.

Parameters:
basicPath - A director name representing the working director, effecting both input and output.

setBasicFileName

public void setBasicFileName(java.lang.String basicFileName)
The setter of the basicFileName member.

Parameters:
basicFileName - The file name of output file or files, excluding the suffix (.pdf). If genMultiPdfs = true, it will be automatically add a number to the end to produce a series of output files, starting from 0.

getOutputStreams

public java.io.OutputStream[] getOutputStreams()
The getter of the output streams.

Returns:
An OutputStream set.

setInputFile

public void setInputFile(java.lang.String inputFile)
The setter of the inputFile member.

Parameters:
inputFile - The input file name containing the pre-defined template.

setInputStream

public void setInputStream(java.io.InputStream inputStream)
The setter of the inputStream member.

Parameters:
inputStream - An InputStream object containing the pre-defined template.

setOutStream

public void setOutStream(java.io.OutputStream outStream)
The setter of the desStream member.

Parameters:
outStream - An OutputStream object containing the filled pdf stream.

setOutStreams

public void setOutStreams(java.io.OutputStream[] outputStreams)
The setter of the outputStreams member.

Parameters:
outputStreams - An OutputStream set containing the multiple filled pdf streams.