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

Free Support Forum - aspose.com

Chart legend entry missing from the PDF output of chart

Hello,

I am using Aspose.Cells v9.0.7 to generate PDF of chart - "RenderTest_33" in the attached excel file. In the PDF output, legend entry is missing.

Following code is used to generate the output:

void chartToPDF() throws Exception {
Workbook workbook = new Workbook("Test_33.xlsm");
WorksheetCollection ws = workbook.getWorksheets();
String worksheetName = "divisional analysis";
Chart chart = ws.get(worksheetName).getCharts().get("RenderTest_33");
chart.toPdf("D:\\RenderTest_33_aspose_9.0.7.pdf");
}

Can you please analyse this issue.

Thanks,
Neha

Hi Neha,


Thank you for sharing the sample. Please try the case against the latest version of Aspose.Cells for Java 16.10.2 (attached) as it produces correct results (attached).

Hello,


Thanks for your reply.

I have tested this issue with the latest version of Aspose.cells - v16.10.2 but unfortunately, this issue is still reproducible. I have attached the PDF output taken using the latest version for your reference.

Can you please analyse it again. And can you please make sure that you are using the same sample code as provided earlier.

Thanks,
Neha

Hi Neha,


Thank you for writing back.

I am afraid, I am still not able to replicate the said issue on my side (please check attached snapshot). Please provide following details for further investigation.

  • Operating system version & architecture
  • JDK vendor, version & architecture
  • JVM arguments, if any
  • Display/resolution settings of the machine
  • Locale of the machine

Furthermore, please perform the test again by downloading the input spreadsheet from this thread just to make sure that we are operating on the same sample.

Hi again,


Upon further reviewing the case, we have noticed that there is difference of fonts between the resultant PDF files (yours and mine) which could be the cause of the problem. If you check the Fonts tab of the Document Properties of both PDF files, you will notice that your PDF file has embedded Arial Unicode font whereas mine has SimSim. Please find the attachment for the TTF files of SimSim font family, and give the scenario another try after installing them on your system. In case the problem persists, please share the resultant PDF file of above test along with the details as requested in the previous response.

Please note, attached font files have been taken from a Windows 10 installation and have been shared here for testing purposes only. In case you wish to use these files in production environment, please be sure to go through the vendor’s EULA.

Hello,


Thanks for your reply.

The issue might be because of difference in fonts. The fonts that you have shared are already installed on my system but still the font in the PDF output on my system is Arial Unicode.

If you will check the actual font used in the excel file, it is - HelveticaNeueLT Std which is not installed on my machine. So, Arial Unicode is getting picked up by Aspose on my machine and SimSun-ExtB is getting picked up on your machine.

Here are the details requested by you in your previous post:

Operating System - Windows 8.1 Pro 64 bit
JDK - jdk-7u45
Resolution - 1920 x 1080
Locale - English (US)



Thanks,
Neha

Hi Neha,


Thank you for your feedback. I also suspected that the problem is related to the missing fonts only, and it can be fixed by installing the required fonts (Univers 45 Light for Workbook’s default style & HelveticaNeueLT Std for legend entries). However, if you cannot install the required fonts, you can also substitute them with the available ones, that could produce closer results. I am researching this option and I will share my feedback after performing tests.

That said, could you please also share the Arial Unicode font file(s) from your machine? I will also check why API is picking Arial Unicode and not SimSun for this scenario.

Hi again,


One way to fix the said problem is to change the font for the legend in the chart. Please check the following piece of code, and give it a try on your side. Please note, the best solution is to install the required fonts in your environment otherwise there are alternative approaches (one suggested as follow) which will produce correct result but content style & size will be a bit different.

Java

<span style=“background-color: rgb(255, 255, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>Workbook book = <span class=“kwrd” style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>new<span style=“background-color: rgb(255, 255, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”> Workbook(dir + “Test_33.xlsm”);
Worksheet sheet = book.getWorksheets().get(“divisional analysis”);
Chart chart = sheet.getCharts().get(0);
System.out.println(chart.getLegend().getFont().getName());
chart.getLegend().getFont().setName(“SimSun-ExtB”);
System.out.println(chart.getLegend().getFont().getName());
chart.calculate();
chart.toPdf(dir + “SimSun-ExtB.pdf”);

Hi Neha,


There could be another solution to the said problem while using Font Substitution mechanism offered by Aspose.Cells APIs that allows you to store the substituted font list against a particular missing font. The API picks the substituted font instead of looking for the required font or substituting it with any available one. Unfortunately, the font substitution does not seem to work for Chart.toPdf method therefore I have raised it with the product team under the ticket CELLSJAVA-42036. Please allow us some time to look further into this matter and get back to you with updates in this regard.

Java

Workbook workbook = new Workbook(dir + “Test_33.xlsm”);
System.out.println(workbook.getDefaultStyle().getFont().getName());
FontConfigs.setFontSubstitutes(“HelveticaNeueLT Std”, new String []{“Arial”});
FontConfigs.setFontSubstitutes(workbook.getDefaultStyle().getFont().getName(), new String []{“Arial”});
System.out.println(FontConfigs.getFontSubstitutes(“HelveticaNeueLT Std”)[0]);
System.out.println(FontConfigs.getFontSubstitutes(workbook.getDefaultStyle().getFont().getName())[0]);
workbook.getWorksheets().get(“divisional analysis”).getCharts().get(0).toPdf(dir + “Arial.pdf”);

Hi again,


This is to update you that the ticket logged earlier as CELLSJAVA-42036 has been marked resolved. We will shortly share the fix here for your testing.
Hi,

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

Let us know your feedback.

Thank you

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


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