Chart image generated using Chart.ToImage: text not visible


#1

Hi,
our customer has this issue:
we use aspose cells version 17.8 and aspose words 16.12.0 and when we get the image of a chart from a workbook using Chart.ToImage and then insert it into Word document, using ImageData.setImage, the resulting image as no text.

We try to reproduce this issue locally but we can not.
Do you have any idea what could be the possible cause of this issue? Could it be something related to the customer application server?

We use this code to read the image from Excel:
public InputStream getChart(String sheet, String name) {
if(sheet == null) {
return null;
}
InOutStream inOutStream = new InOutStream();
try {
Worksheet worksheet = currentWorkbook.getWorksheets().get(sheet);
Chart chart = worksheet.getCharts().get(name);
chart.toImage(inOutStream, AsposeCellsUtils.getImageOrPrintOptions());
} catch (Exception e) {
return null;
}
return inOutStream.toInputStream();
}

We use this code to insert the image into Word:
Shape shapeToReplace = (Shape) sdt.getChild(NodeType.SHAPE, 0, true);
if (shapeToReplace == null) {
throw new OOXMLException(“Image object not present inside picture content control”);
}

        InputStream imageStream = res.getImageStream();
        try {
            ImageData imageData = shapeToReplace.getImageData();
            if (imageStream == null) {
                imageStream = this.getClass().getResourceAsStream("/images/imagePlaceholder.png");
                sdt.isShowingPlaceholderText(true);
                imageData.setImage(imageStream);
                resizeShape(shapeToReplace, imageData);
            } else {
                imageData.setImage(imageStream);
                if (sdt.isShowingPlaceholderText()) {
                    resizeShape(shapeToReplace, imageData);
                    sdt.isShowingPlaceholderText(false);
                }
            }
        } catch (Exception e) {
            throw new OOXMLException(e);
        }

This is an example of the result:
chart.png (3.2 KB)

Thanks
Giulio


#2

@giulio.andolfi

Thanks for using Aspose APIs.

Please download and try the latest version and see if it makes any difference and resolves your issue.

If your issue is still not resolved, please provide us your MS Excel workbook containing the chart and the output MS Word document for our investigation. We will look into it and help you asap.


#3

Thanks for your replay.

We could try to test the last version, but locally we have not any issues and we thinking that it works fine.
The issue only occurs on the customer’s system and now it is not possible update them to the last version.

Locally our application runs with wildfly 9 and jdk1.8.0_152 64 bit installed on window 10.

The customer’s system has these features

jBoss EAP 6.4.13 GA (AS 7.5.13.Final-redhat-2), openjdk version 1.8.0_131, OpenJDK Runtime Environment (build 1.8.0_131-b12), OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode), and Apache 2.4 will be the middleware versions installed on the red Hat 7.2 application servers.

Could be the issue caused from the system installation?

Thanks
Giulio


#4

@giulio.andolfi

Thanks for using Aspose.Cells.

May be your problem is occurring because of fonts. It might be the case that your one machine does have all the proper and needed fonts and other machine has missing fonts.

Please collect all the required fonts from your one machine which is working and place them in some directory on other machine. Suppose, you have placed the fonts in /usr/temp/myFonts directory, then set the fonts folder as below.

Java

String fontFolder="/usr/temp/myFonts";
//fontFolder = "C:/temp/myFonts";//This is for Windows <<<
FontConfigs.setFontFolder(fontFolder, true);

Please note, you must execute this code before you execute any other Aspose.Cells code. For more information, please see these articles.

Article Links:


Besides, you should find the reason why your customer is not able to get right report. You may create a simple test project that only use Aspose.Cells with sample Excel file and let your customer try it.

Java

String dir = "D:/Aspose/...../";
File file = new File(dir + "test.xlsx");

Workbook wb = new Workbook(file.getAbsolutePath());
Worksheet sheet = wb.getWorksheets().get(0);
Chart chart = sheet.getCharts().get(0);

chart.toImage(dir +"chart.png");

#5

Thanks for your advice.
I will let you know as soon as possible
Giulio


#6

Hi all,
the problem is not caused by the fonts but the type of the chart.
Many thanks for your collaboration.


#7

CHART_WITH_ISSUE.zip (10.6 KB)

Hi @shakeel.faiz,
I have attached my excel file with the chart,
You have any idea why this chart has problems when the system reads it with aspose?
This is our method:

public InputStream getChart(String sheet, String name) {
        if(sheet == null) {
            return null;
        }
        InOutStream inOutStream = new InOutStream();
        try {
            Worksheet worksheet = currentWorkbook.getWorksheets().get(sheet);
            Chart chart = worksheet.getCharts().get(name);
            chart.toImage(inOutStream, AsposeCellsUtils.getImageOrPrintOptions());
        } catch (Exception e) {
            return null;
        }
        return inOutStream.toInputStream();
    }

Thanks
Giulio


#8

@giulio.andolfi

Thanks for using Aspose APIs.

Please execute the following code and share the output Pdf of your chart. You can also add comments inside the output Pdf for highlighting the problem in precise manner.

Download Link:
outputChart.pdf (15.2 KB)

Java

Workbook wb = new Workbook(dirPath + "CHART_WITH_ISSUE.xlsx");

wb.calculateFormula();

Worksheet ws = wb.getWorksheets().get("Waterfall D.2.1.3");

Chart ch = ws.getCharts().get(0);
ch.toPdf(dirPath + "outputChart.pdf");

#9

@shakeel.faiz

Thanks for your collaboration.

This is the output from my pc:
outputChart.pdf (31.8 KB)

The chart is ok.

This is the output from customer pc:
chart.png (524 Bytes)

The chart has not the text.

The first one is the output from the code that you sent me today, the second one is the output that you sent me the january ten.
We use aspose cells version 17.8.


#10

@giulio.andolfi

Thanks for your feedback and using Aspose APIs.

Please try the most recent version i.e. 18.2. Create a very simple console application i.e. runnable JAR file and run it on Windows and Linux machines and check the results. The console application should run the code as I have shared in the post #8 i.e.

In case of error, please share the code, runnable JAR file as well as the output Pdfs of both machines. These things will help us look into this issue further and we will replicate and log the issue in our database for investigation and for a fix.