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

Free Support Forum - aspose.com

Chart to Image/PDF conversion gives blank image


I am using Aspose cells
In context of the attached excel document, if we try to generate image or PDF of Chart 1 in Charts worksheet, we get a blank image and PDF.

Here’s the API being used for converting chart to image :-

And code snippet for converting chart to PDF :-
private File chartToPdf(Workbook workbook, com.aspose.cells.Chart chart, NameValue[] outputFormatProperties) throws IOException,Exception {
WorksheetCollection ws = workbook.getWorksheets();
ChartShape cshape = chart.getChartObject();
int sheetIndex = ws.add();
com.aspose.cells.Worksheet worksheet = ws.get(sheetIndex);
double chartWidthInInches = chart.getChartObject().getWidthInch();
double chartHeightInInches = chart.getChartObject().getHeightInch();
boolean defaultApproach = true;
if (chartWidthInInches > maxExcelColWidthInInches || chartHeightInInches > maxExcelRowHeightInInches) {
// 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”;
//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);
//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();
PdfSaveOptions pdfSaveOptions = getPdfSaveOptions();
//Setting Print area to first cell only as the chart is contained in the first cell (A1:A1)
if (defaultApproach) {
// Save the workbook
File outputPdfFile = OfficeResourceUtility.createTemporaryFile(".pdf");
workbook.save(outputPdfFile.getAbsolutePath(), pdfSaveOptions);
workbook.save(“c:\temp\test.xlsx”, SaveFormat.XLSX);
return outputPdfFile;

Can you please verify this issue.

Attached the problematic excel document & blank PNG & PDF outputs for reference.



Thanks for providing us template files, sample code and details.

Please try our latest version/ fix: Aspose.Cells for Java (Latest Version)

Well, I checked your template file and it has blank charts in it (there are three charts in it, Chart 2 which is blank, two chart have similar name “Chart 1”, one of them is blank —, so only one chart is not blank out of 3 (you may click Page Layout|Selection Pane to get view of all the shapes by opening the Excel file in MS Excel)). I have tested your scenario/ case using your template file and sample code below with v8.4.2.8, it works fine and as expected:
Sample code:

Workbook workbook = new Workbook(“Book1+Chart+not+appearing.xlsx”);


Let us know if you still find the issue.

Thank you