Debugging excel fonts issues

Hello,

We use Aspose.Cells for converting excel charts and tables into different formats. A lot of time we face fonts related issues where the fonts used in output are not the same as the fonts used in excel.

In many of these cases, we are unable to figure out whether the issue is because the font is not installed on the machine or if it is an aspose bug. Sometimes it seems that the font used in excel is installed on the machine but their names are not an exact match.

It would be easier for us to figure out such issues if we could know which font was searched for by aspose and was not found and which font was used as its fallback. So, are there any logging/debug options in aspose through which we can get this information?

Thanks,
Neha

@Neha_Gautam,

Thanks for your query.

Well, mostly such an issue should be due to missing fonts (used in the workbook) on the machine (where you are executing your sample code), so it might not be a bug in Aspose.Cells APIs. Please note, regarding font substitutions, by default, Aspose.Cells checks the workbook’s default font to see if it can be used to show the text properly. If not, Aspose.Cells will search all the fonts in the specified folders. To search proper font in substitution, Aspose.Cells also checks whether the given chars’ glyph is in that font or not.

Anyways, if you find any issue (where the underlying font is there but Aspose.Cells uses some other font), let us know with details, sample code, font files and template files, we will check it soon.

When rendering MS Excel to PDF/image, you can use the API, i.e, set WarningCallback attribute in PdfSaveOptions/ImageOrPrintOptions to get or instantiate the fonts substitution info. See the sample code segment for your reference:
e.g.
Sample code:

 class WarningCallback : IWarningCallback
{
public void Warning(WarningInfo info)
{
if (info.WarningType == WarningType.FontSubstitution)
{
Console.WriteLine(info.Description);
}
}
} 

Hope, this helps a bit.

Hello,

Thanks for your reply.

While rendering excel to image, I was able to set WarningCallback attribute in ImageOrPrintOptions but when rendering excel chart as PDF, I couldn’t find any method which can be used to set the WarningCallback.

Following code is used to generate the chart’s PDF:

Workbook workbook = new Workbook(“test.xlsx”);
WorksheetCollection ws = workbook.getWorksheets();
String worksheetName = “test”;
Chart chart = ws.get(worksheetName).getCharts().get(“test”);
chart.toPdf(“output.pdf”);

Is there a way to set WarningCallback while rendering chart as PDF?

Thanks,
Neha

@Neha_Gautam,

I am afraid, WarningCallback attribute belongs to PdfSaveOptions and ImageOrPrintOptions. This attribute is not there under toPDF() method of Chart. I am afraid, you have to cope with it by yourself. You got to hide or remove other contents or copy the chart into a new worksheet (only) and then render PDF of the workbook to avail this option. Alternatively, you have to render image of the chart instead of PDF file format get those warning details.