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

Free Support Forum - aspose.com

Timetaken to cnvert from Excel to PDF

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());

}

Hi Abhinav,

Thanks for your posting and using Aspose.Cells.

If your source Excel file which you are converting to PDF is large then it will definitely take some time during conversion.

Kindly post your source Excel file so that we could test this issue at our end. We will look into it and update you asap.

Hi,

Thanks for prompt response. Attached is one of the source excel files

Hi Abhinav,

Thanks for your sample file and using Aspose.Cells.

Please download and use the latest version: Aspose.Cells
for Java v8.1.1.4
it should fix your issue.

We tested this issue with the following code and it took 2922 milliseconds which means 2.9 seconds. I have also attached the generated pdf for your reference.

Java


String filePath = “F:\Shak-Data-RW\Downloads\ReportResult_2014-07-22_10_32_49.xls”;


Date d3 = new Date(System.currentTimeMillis());


Workbook workbook= new Workbook(filePath);


for(int i=0; i<workbook.getWorksheets().getCount(); i++)

{

Worksheet ws = workbook.getWorksheets().get(i);

ws.autoFitRows(true);

}


//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(0.5);

pageSetup.setRightMargin(0.5);

pageSetup.setTopMargin(0.5);

pageSetup.setZoom(120);


//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=“Report Name”;//setting header

pageSetup.setFooter(2, " &12 &B"+footerTitle);


PdfSaveOptions saveOpt = new PdfSaveOptions(SaveFormat.PDF);

saveOpt.setAllColumnsInOnePagePerSheet(true);


workbook.save(filePath + “.out.pdf”, saveOpt);


Date d4 = new Date(System.currentTimeMillis());

long diffInMilliseconds =Math.abs(d3.getTime()-d4.getTime());

System.out.println(“TimeTaken for converting excel to PDF =”+diffInMilliseconds);


Console Output:
TimeTaken for converting excel to PDF =2922