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

Free Support Forum - aspose.com

Source and Copyright elements in Chart are not on the same height in PDF Output as they are shown in Excel

Hi,

I am using Aspose.Cells v8.6.1
On converting Chart 2 in attached excel to PDF, Source and Copyright elements in Chart are not on the same height in PDF Output as they are shown in Excel.

I have attached the Excel file, pdf taken using aspose, and PDF taken using MS-Excel.

For reference the sample code:
private static void chartToPDF() throws Exception {
Workbook workbook = new Workbook(“D:\UMI-LN_Model_Quark testing.xlsx”);
WorksheetCollection ws = workbook.getWorksheets();
Chart chart = workbook.getWorksheets().get(0).getCharts().get(“LIB_Column_061930”);
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(“d:\temp\Aspose_PDF.pdf”, pdfSaveOptions);
}


Can you please analyse this issue.

Thanks,
Neha Gautam

Hi,


I observed the issue as you mentioned by using your sample code with your template file. I found that Source and Copyright elements in chart are not on the same height/location in the output PDF file format.
e.g
Sample code:

Workbook workbook = new Workbook(“Test2.xlsx”);
WorksheetCollection ws = workbook.getWorksheets();
Chart chart = ws.get(0).getCharts().get(0);
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(“out1.pdf”, pdfSaveOptions);

I have logged a ticket with an id “CELLSJAVA-41569” for your issue. We will look into it to figure it out soon.

Thank you.

Hi,


Could you please try our latest version/fix: Aspose.Cells for Java v8.6.2.4.
And please try Chart.toPdf() method directly. If you still find the issue, let us know with some screen shots highlighting the issue.

Thank you.

Hello,


I tried your latest fix - Aspose.Cells v8.6.2.4. I used chart.toPdf() method to generate the PDF but unfortunately the issue still exists. The Source and Copyright elements are not on the same height.

For your reference, I have attached the PDF generated using Aspose and the one generated using Excel.

Can you please analyse this issue.

Hi,


Thanks for your sample files and details.

You are right. I can still see the issue using the new Chart.toPDF() method with v8.6.2.4 (latest version/fix), the bottom Text boxes (shape elements) on the chart are not placed correctly, see the screen shot for your reference here:
http://prntscr.com/9e0akj

e.g
Sample code:

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

We will look into your issue soon.

Thank you.

Hi,

Thanks for using Aspose.Cells.

We have fixed the issue CELLSJAVA-41569.

Please download and try the latest fix: Aspose.Cells for Java v8.6.2.6 and let us know your feedback.

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


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