Please find the source code below. It generates just a single page taking 40 seconds for the save method to execute. The culprit seems to be TextState API implementation . And this is the reason why I think the Aspose 4.5 API for java is not production ready (This version and com.aspose.pdf package was specifically recommended to be used by you in another forum thread ). We cannot have API’s like that which is open to use without specific documentation . If each row we need to set a different cell text state ,this is going take forever if the pages that is going to be generated is more than 50.
package com.arbitron.pdflibrary;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Locale;
import com.aspose.pdf.BorderInfo;
import com.aspose.pdf.BorderSide;
import com.aspose.pdf.Cell;
import com.aspose.pdf.CellBorderStyle;
import com.aspose.pdf.Color;
import com.aspose.pdf.Document;
import com.aspose.pdf.DocumentInfo;
import com.aspose.pdf.FontStyles;
import com.aspose.pdf.HorizontalAlignment;
import com.aspose.pdf.License;
import com.aspose.pdf.MarginInfo;
import com.aspose.pdf.Page;
import com.aspose.pdf.PageInfo;
import com.aspose.pdf.PageSize;
import com.aspose.pdf.Row;
import com.aspose.pdf.Table;
import com.aspose.pdf.TextFragment;
import com.aspose.pdf.TextState;
import com.aspose.pdf.VerticalAlignment;
public class TestAsposePerfIssue {
public static void main(String[] args){
Locale.setDefault(Locale.ENGLISH);
License lic = new License();
try {
lic.setLicense(new FileInputStream(“d:\work\Aspose.Total.Java.lic”));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Document doc = getPdf();
Page page = doc.getPages().add();
Table table = new Table();
table.setRepeatingRowsCount(1);
table.setColumnWidths(“50 50 50 50 50 50 50 50 50 50”);
Color color = Color.getWhite();
table.setBackgroundColor(color);
MarginInfo marginInfo = new MarginInfo();
float marginLeft = 2;
float marginRight = 2;
float marginTop = 2;
float marginBottom = 2;
marginInfo.setLeft(marginLeft);
marginInfo.setRight(marginRight);
marginInfo.setTop(marginTop);
marginInfo.setBottom(marginBottom);
table.setDefaultCellPadding(marginInfo);
int numRows = 10;
int numCols = 10;
for (float i=1;i <= numRows;i++){
Row row = table.getRows().add();
BorderInfo borderInfo = new BorderInfo(BorderSide.None);
row.setDefaultCellBorder(borderInfo);
java.awt.Color awtdefaultbgcolor = null;
if(i % 2 == 0){
awtdefaultbgcolor = java.awt.Color.GRAY;
}else if(i % 3 == 0){
awtdefaultbgcolor = java.awt.Color.YELLOW;
}else{
awtdefaultbgcolor = java.awt.Color.BLUE;
}
color = Color.fromArgb((short)awtdefaultbgcolor.getRed(), (short)awtdefaultbgcolor.getGreen(), (short)awtdefaultbgcolor.getBlue());
row.setBackgroundColor(color);
TextState textState = new TextState();;
textState.setFontStyle(FontStyles.Bold);
textState.setFontSize(12);
textState.setForegroundColor(java.awt.Color.BLACK);
row.setDefaultCellTextState(textState);
for(int j=0;j < numCols;j++ ){
Cell cell = row.getCells().add();
CellBorderStyle cellBorderStyle = new CellBorderStyle(color, true);
cellBorderStyle.setLineWidth(0.1f);
borderInfo = new BorderInfo(BorderSide.All, cellBorderStyle);
cell.setBorder(borderInfo);
cell.setVerticalAlignment(VerticalAlignment.Center);
cell.setAlignment(HorizontalAlignment.Center);
if(i == 1){
TextFragment text = new TextFragment("Header "+ j);
cell.getParagraphs().add(text);
}else{
TextFragment text = new TextFragment("Value “+ i + “:” + j);
cell.getParagraphs().add(text);
}
}
}
page.getParagraphs().add(table);
long before = System.currentTimeMillis();
doc.save(“TestAsposePerf.pdf”);
long after = System.currentTimeMillis();
System.out.println(“Time taken for save :” + ((after - before) / 1000) + " Seconds”);
}
public static Document getPdf(){
Document pdf = new com.aspose.pdf.Document();
DocumentInfo docInfo = pdf.getInfo();
docInfo.setAuthor(“Perf”);
PageInfo pageInfo = pdf.getPageInfo();
MarginInfo marginInfo = pageInfo.getMargin();
float marginLeft = 10;
float marginRight = 10;
float marginTop = 10;
float marginBottom = 10;
marginInfo.setLeft(marginLeft);
marginInfo.setRight(marginRight);
marginInfo.setTop(marginTop);
marginInfo.setBottom(marginBottom);
pageInfo.setHeight(PageSize.getPageLetter().getHeight());
pageInfo.setWidth(PageSize.getPageLetter().getWidth());
pageInfo.isLandscape(true);
return pdf;
}
}