Charts border not appearing correctly

Hi,

I am using aspose-cells-8.5.2.4.

While rendering charts to PDF, border of the chart area is incorrectly rendered in the PDF. For your reference I have attached two excel files containing charts with which the issue is clearly reproducible along with PDFs being generated by Aspose .

Following is the code snippet being used:
Chart chart = worksheet.getCharts().get("Chart 1");
WorksheetCollection ws = workbook.getWorksheets();
Chart chart = ws.get("wo cons charts").getCharts().get("Chart 1");
ChartShape cshape = chart.getChartObject();

int sheetIndex = ws.add();

com.aspose.cells.Worksheet worksheet = ws.get(sheetIndex);

chart.calculate();

double chartWidthInInches = chart.getChartObject().getWidthInch();
double chartHeightInInches = chart.getChartObject().getHeightInch();

worksheet.getCells().setColumnWidthInch(0, chartWidthInInches);
worksheet.getCells().setRowHeightInch(0, chartHeightInInches);

//Setting the name of the newly added worksheet
String transientSheetName = "TransientWorksheet";
worksheet.setName(transientSheetName);
//Copy the Chart to target Worksheet
worksheet.getShapes().addCopy(cshape, 0, 0, 0, 0);

//Get the new chart and set its height and width accordingly
com.aspose.cells.Chart chart1 = worksheet.getCharts().get(0);

chart1.getChartObject().setHeightInch(chartHeightInInches);
chart1.getChartObject().setWidthInch(chartWidthInInches);

//Make remaining worksheets invisible so that they are not part of the output pdf
for (int i = 0; i < ws.getCount(); i++) {
String sheetName = ws.get(i).getName();
if(!transientSheetName.equalsIgnoreCase(sheetName)){
ws.get(i).setVisible(false);
}
}
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setOnePagePerSheet(true);

worksheet.getPageSetup().setTopMargin(0);
worksheet.getPageSetup().setBottomMargin(0);
worksheet.getPageSetup().setRightMargin(0);
worksheet.getPageSetup().setLeftMargin(0);

worksheet.getPageSetup().setPrintArea("A1:A1");

workbook.save("c:/temp/out-1.pdf", pdfSaveOptions);
Thanks,
Neeraj

Hi Neeraj,


Thank you for contacting Aspose support.

We have evaluated the presented scenario while using the latest version of Aspose.Cells for Java 8.6.0.3, and we are able to notice the problem for the sample spreadsheet ChartBorder1.xlsx. We have logged this incident in our bug tracking system as CELLSJAVA-41505 for further investigation. Please note, the resultant PDF for the sample spreadsheet ChartBorder2.xlsx shows the borders correctly. Please check the attached resultant PDF files for your reference.

Hi Babar,


Thanks for your response.

With regards to sample spreadsheet ChartBorder2.xlsx, you might not be able to observe the problem because of the border color and size.

To recognize the given problem I would suggest to do the following:
1. Change the border color of the chart to Red.
2. Get PDF of the chart from both Aspose and MS Excel.
3. Zoom-in both PDFs, compare and observe the following:
a. Border on left side is not as broad as compared to border on right side.
b. Border on top is not at all visible
c. On right and bottom - slight white space is visible

My conclusion: It seems that chart is rendered a bit more towards top-left, which results in cutting of left and top side and appearance of white space in bottom and left side.

Attaching PDFs generated using Aspose and MS Excel for your reference too.

Thanks,
Neeraj

Hi Neeraj,


Thank you for providing more details.

I have checked the scenario as illustrated in your previous post and I am able to replicate points a) & b) while using the latest version of Aspose.Cells for Java 8.6.0.3 therefore I have logged it under a new ticket CELLSJAVA-41509. We will soon analyze these concerns to figure out if improvements can be done in this regard. Please note, there are no blank white spaces around the borders if you generate the PDF with latest revision (as requested earlier in this thread).

Hi again,


This is to update you that we have exposed the Chart.toPdf method that will be available with next release of Aspose.Cells for Java API to create a PDF directly from the chart. This way you will be able to avoid the issues logged earlier as CELLSJAVA-41509 & CELLSJAVA-41505.

Hi,

Please try our latest version/fix: Aspose.Cells for Java v8.6.1.4 (attached) and use the new method Chart.toPdf() for border issues (CELLSJAVA-41505 and CELLSJAVA-41509).

Using the new method to create chart’s PDF format, you don’t need to copy chart to new worksheet. Please generate PDF directly.

e.g.
Sample code:

String dir = "D:\\1074\\";
Workbook workbook = new Workbook(dir + "ChartBorder1.xlsx");
WorksheetCollection ws = workbook.getWorksheets();
Chart chart = ws.get(0).getCharts().get("Chart 1");
chart.toPdf(dir + “chart.pdf”);

Let us know your feedback.

Thank you.

The issues you have found earlier (filed as CELLSJAVA-41509;CELLSJAVA-41505) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi,

We have tested with 8.6.2.4. Although the output is improved still margin is appearing.

Thanks,
Neha

Hi Neha,


Thank you for sharing your feedback.

Could you please clarify, which ticket (CELLSJAVA-41505, CELLSJAVA-41509) have you referenced in your recent post? Please also share the PDF generated on your end while highlighting the problematic area(s).

It’s CELLSJAVA-41509


Thanks,
Neeraj

Hi,


I have evaluated your issue “CELLSJAVA-41509” using your original template Excel file with Aspose.Cells for Java v8.6.2.4 bit. I found it works fine, even it renders better image as compared to what is shown in MS Excel’s print preview for the chart. I used the following sample code with your template file:
e.g
Sample code:

String dir = “f:\files\”;
Workbook workbook = new Workbook(dir + “ChartBorder2.xlsx”);
WorksheetCollection ws = workbook.getWorksheets();
Chart chart = ws.get(0).getCharts().get(“Chart 1”);
chart.toPdf(dir + “out1ChartBorder2.pdf”);

I have attached the output PDF file here. Could you check and let us know (via screen shot(s)) what went wrong for your issue, we will check it further.

Thank you.


Thanks for your reply.


I am using Aspose.Cells v8.6.2.4. I have generated the PDF using chart.toPdf() method. But the white space around right and bottom borders still exist.

You may not be able to observe the problem because of the PDF’s size. If you will Zoom-in the PDF, the white space will be clearly visible.

I am attaching a screenshot which may help you in identifying the issue. I am also attaching the PDF generated using Aspose.Cells v8.6.2.4.

Thanks,
Neeraj

Hi,


Well, this is a minor difference and can only be seen when we set the zoom level to higher value e.g “400%” in Adobe acrobat. Anyways, we have logged your concerns against your issue “CELLSJAVA-41509” into our database. Our concerned developer from product team will look into it if we could fix it.

Thank you.