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

Free Support Forum - aspose.com

Position of Axis title different in PDF output of chart in comparison to source excel

Hi,

I am using Aspose.Cells v8.5.2.4
On converting Chart 1 in attached Excel doc to PDF, the position of label ‘Axis Title’ doesn’tappear at the same location as in source excel.

Here’s the code reference of copying chart to new worksheet & saving to PDF:
private static void chartToPDF() throws Exception {
Workbook workbook = new Workbook(“C:\Innovation_Chart1.xlsx”);
WorksheetCollection ws = workbook.getWorksheets();
Chart chart = workbook.getWorksheets().get(0).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();
boolean defaultApproach = true;
if (chartWidthInInches > 18 || chartHeightInInches > 5) {
// The approach being followed here is to iterate as many columns as colwidth in pixels & set each column width equal = 1 pixel.
// Similarly for chart height, iterate through as many rows as row height & set each row height = 1 pixel.
// This is being done to fit in large charts that have height & width beyond maximum row/col dimensions & white spaces around
// the chart.

double chartWidthInPixels = chart.getChartObject().getWidth();
double chartHeightInPixels = chart.getChartObject().getHeight();
// Deliberately including one more column because Aspose considers the last column adjacent to chart which leads to white space
// on right of chart
for (int i = 0; i <= chartWidthInPixels; i++) {
worksheet.getCells().setColumnWidthPixel(i, 1);
}

// Deliberately including one more row because Aspose considers the last row adjacent to chart which leads to white space
// below the chart.
for (int i = 0; i <= chartHeightInPixels; i++) {
worksheet.getCells().setRowHeightPixel(i, 1);
}
defaultApproach = false;
} else {
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 Second 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);
//Setting Print area to first cell only as the chart is contained in the first cell (A1:A1)
if (defaultApproach) {
worksheet.getPageSetup().setPrintArea(“A1:A1”);
}
// Save the workbook
workbook.save(“C:\Chart 1.pdf”, pdfSaveOptions);
}


Also,attached the sample excel & outputs.

Thanks,
Jaspreet

Hi,


Thanks for the template file and sample code.

After an initial test, I observed the issue as you mentioned. I found the position of y-axis title of the chart doesn’t appear at the same location as in the source Excel file. I used the template file provided by you with your sample code to reproduce the issue as per your attached screen shot. I have logged a ticket with an id “CELLSJAVA-41517” for your issue. We will look into it to figure it out soon.

Thank you.

Hi Jaspreet,

This is to inform you that we have fixed the problem logged earlier as CELLSJAVA-41517. We will shortly provide the fix here after ensuring the quality and incorporating other enhancements.

Hi,

Thanks for using Aspose.Cells.

Please try the latest version: Aspose.Cells for Java 8.6.1 we have fixed this issue. Let us know your feedback.

Hi,


We have tested the given issue with Aspose Cells 8.6.2.

Unfortunately the problem still appears.

Can you please look into this?

Thanks,
Neeraj

Hi Neeraj,


I have evaluated the scenario again while using the latest version of Aspose.Cells for Java 8.6.2. By looking at the resultant PDF, I believe the issue has been resolved. Please check the attached snapshots and resultant PDF. If you are getting different result then please share the PDF from your side.

Hello,


I am using chart.toPdf() method of Aspose.Cells v8.6.2.4 to generate the chart’s PDF. Unfortunately, this issue still exists.

I am attaching the PDF taken using Aspose and using Excel. Along with that I have attached a Screenshot to compare these two PDFs. I hope that will help in better understanding of the issue.

In the Screenshot, you will easily see the difference in the position of Axis title.

Thanks,
Neeraj

Hi,

Thanks for your screenshots and using Aspose.Cells.

The difference is negligible and minutely noticeable. Please note we cannot do exactly 100% same like MS-Excel, because MS-Excel uses Native APIs and we rely on .NET and JAVA APIs to render these images so there will always be some difference. Thanks for your understanding.