We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Batch (template-based) document generation in Aspose.Words for Java

Hi,

I need to generate documents in bulk (based on template) from a set of XML data files. For example, I need to generate 50,000 bank statements (PDFs) from XML data files (1 data file per statement output) and assume that the template for the bank statement is setup in Word and contains multiple data fields.

1. What is the best mechanim to use for such batch generation of documents? Can I use mail merge or should I consider something else? Assume that such batch document generation will be asynchronous and performed outside of business hours.

2. What performance consideration do I need to be aware of when using Aspose.Words for batch document generation?

Rgs

Kunal.

Hi Kunal,


Thanks for your inquiry. You just need to perform mail merge several times for each XML file you have. Please see the following code:
//Create dummy datasource
DataTable data = new DataTable();
data.getColumns().add(“FirstName”);
data.getColumns().add(“LastName”);
data.getColumns().add(“City”);
data.getColumns().add(“Company”);
//add dummy data
data.getRows().add(new Object[] { “Den”, “Smith”, “London”, “Apple” });
data.getRows().add(new Object[] { “Steve”, “Martin”, “Berlin”, “Stern” });
data.getRows().add(new Object[] { “Nina”, “Burn”, “Tallin”, “IBM” });

//Open template document
Document doc = new Document(getMyDir() + “Field-modified.docx”);

int counter = 0;
//Loop though all record in our datasource
for (DataRow row : data.getRows())
{
//Clone template
Document temp = (Document)doc.deepClone(true);
//Execute mail merge
temp.getMailMerge().execute(row);
//Save document
temp.save(getMyDir() + “out_{0}.” + counter);
counter++;
}

I hope, this helps.

Best regards,