Hi,
I am using Aspose.Cells v8.6.1.6
I am converting Chart 1 in the attached excel file to PDF using chart.toPdf(fileName) api. The PDF is not generated after the execution of line 5. Its size remains 0 KB. The pdf gets generated only after the entire execution of the program is completed.
For reference the sample code:
private static void chartToPDF() throws Exception { //line 1
Workbook workbook = new Workbook(“test.xlsx”); //line 2
WorksheetCollection ws = workbook.getWorksheets(); //line 3
Chart chart = workbook.getWorksheets().get(0).getCharts().get(“Chart 1”); //line 4
chart.toPdf(“D:\test.pdf”); //line 5
System.out.println(“PDF is saved at location : D:\test.pdf”); //line 6
}
I even used workbook.dispose() method after line 5 to release resources but it didn’t work.
Can you please analyse this issue and see if there is any workaround for this problem?
Thanks,
Neha Gautam
Hi,
The issue is that the pdf gets generated after the whole program has executed and the jvm gets closed. But the pdf is not generated just after the execution of chart.toPdf() method. In the following sample code, if you will apply a breakpoint on line 6 and check if the pdf is generated at this point, you will see that the pdf is of 0KB size and it wont open.
Sample code:
private static void chartToPDF() throws Exception { //line 1
Workbook workbook = new Workbook(“test.xlsx”); //line 2
WorksheetCollection ws = workbook.getWorksheets(); //line 3
Chart chart = workbook.getWorksheets().get(0).getCharts().get(“Chart 1”); //line 4
chart.toPdf(“D:\test.pdf”); //line 5
System.out.println(“PDF is saved at location : D:\test.pdf”); //line 6
}
Can you please analyse this issue.
Thanks,
Neha Gautam
There seems to be a problem with the resource cleaning in the method chart.toPdf(…).
For better understanding kindly execute the following code:
private static void chartToPDF() throws Exception { //line 1
Workbook workbook = new Workbook(“test.xlsx”); //line 2
WorksheetCollection ws = workbook.getWorksheets(); //line 3
Chart chart = workbook.getWorksheets().get(0).getCharts().get(“Chart 1”); //line 4
chart.toPdf(“D:\test.pdf”); //line 5
System.out.println(“PDF file deleted:” + new File(“D:\test.pdf”).delete());
}
You will see that you will not be able to delete the PDF file which has been generated. It will print the following:
PDF file deleted: false
Whereas if we do the same thing with chart.toImage(…) it works fine.
Thanks,
Neha
Hi,
Thanks for providing us further details.
You are right. There looks to me an issue with resources’ releasing in Chart.toPdf() method as you pointed out. After adding your suggested line to the code segment would print:
PDF file deleted: false
I have logged your comments to attached with your existing ticket “CELLSJAVA-41578” into our database. Our concerned developer will look into the details and try to figure your issue out soon.
Once we have any update on it, we will let you know here immediately.
Thank you.
Hi,
Thanks for using Aspose.Cells.
This is to inform you that we have fixed your issue CELLSJAVA-41578 now. We will soon provide the fix after performing QA and including other enhancements and fixes.
The issues you have found earlier (filed as CELLSJAVA-41578) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.