Hi All,
We have been using Aspose cells to convert excels to PDF using below code. The time taken to convert from excel to PDF is way more. Is there something that can be done to reduce this.
Or can we chnage anything in the approach.
Below is the code snippet. This took 26 seconds
-----------------------------
//Step 8:Saving the workbook
Workbook workbook=reportBean.getWb();//gets the workbook
try{
workbook.save(reportBean.getOutputPath());//saves the workbook
if(inputParameters.getReportOutputType()==ONE)//if PDF
{
Date d3 = new Date(System.currentTimeMillis());
for(int i=0; i<workbook.getWorksheets().getCount(); i++)
{
Worksheet ws = workbook.getWorksheets().get(i);
ws.autoFitRows(true);
}
log.debug("Setting page title for PDF options");
//Accessing the first worksheet in the Excel file
Worksheet sheet = workbook.getWorksheets().get(0);
PageSetup pageSetup = sheet.getPageSetup();
//Setting the orientation to Portrait
pageSetup.setOrientation(PageOrientationType.PORTRAIT);
pageSetup.setLeftMargin(HALF);
pageSetup.setRightMargin(HALF);
pageSetup.setTopMargin(ONE);
pageSetup.setZoom(ONETWENTY);
//Setting the printing order of the pages to over then down
pageSetup.setOrder(PrintOrderType.OVER_THEN_DOWN);
pageSetup.setPrintTitleColumns("$A:$A");
//Defining row numbers 1 - 2 as title rows
pageSetup.setPrintTitleRows("$1:$7");
pageSetup.setFooter (1, " &12 &B Page &P of &N");
String footerTitle=INSTITUTION_PAGE+reportBean.getReportSectionBean().getReportName();//setting header
pageSetup.setFooter(2, " &12 &B"+footerTitle);
log.debug("Setting page title for PDF options : END");
//Save the document in PDF format
log.debug("saving to PDF");//saving start
String pdfOutputPath=reportBean.getOutputPath();
pdfOutputPath=pdfOutputPath.substring(0,pdfOutputPath.length()-THREE);
pdfOutputPath=pdfOutputPath+"pdf";
reportBean.setOutputPath(pdfOutputPath);
PdfSaveOptions saveOpt = new PdfSaveOptions(SaveFormat.PDF);
saveOpt.setAllColumnsInOnePagePerSheet(true);
workbook.save(reportBean.getOutputPath(), saveOpt);
log.debug("saving to PDF: END");//saving end, tis took 26 seconds
Date d4 = new Date(System.currentTimeMillis());
long diffInMilliseconds =Math.abs(d3.getTime()-d4.getTime());
log.debug("TimeTaken for converting excel to PDF ="+diffInMilliseconds+MILLI_SEC);
}
}
catch(Exception exception){
log.debug(exception.getMessage());
}