How to add Windows fonts in Aspose.Cell in AWS Lambda?

Hi team

I would like use Aspose.Cell Java(Or C#) to convert excel file to PDF in AWS Lambda. I need add some Windows Fonts(like mingliu) which are used in Excel files. Is there any document or sample code I can refer? Before purchasing a license, I would need confirm it. Thanks.

Regards,
Chenxg

@chenxg,

There is no specific Java document for the purpose but you may refer to the document for your reference.

@Amjad_Sahi

Thanks, I have deployed that sample code successfully. Is there some reference code for Aspose.Cell as well?

Regards,
Chenxg

@chenxg,

There is no specific document in Aspose.Cells Docs. We plan to add similar document soon.

See the following sample code with comments for your reference:

//first, get font bytes of font1 and font2 on Lambda
//second, set font1 and font2
FontConfigs.SetFontSources(new FontSourceBase[] {new MemoryFontSource(bytesOfFont1), new MemoryFontSource(bytesOfFont2) });

//then, go on
Workbook wb = new Workbook(); 

Please note, for the first step to get font bytes, you may refer to the document I shared earlier for your reference.

Hope, this helps a bit.

@Amjad_Sahi

Thanks, I get an error message of “The type initializer for ’ ’ threw an exception.: CellsException” .It seems thast I need install “libgdiplus” into .Net Core Lambda function, I think. However, I did not find a good document. Is there any guideline I can refer? By the way, I do find some fonts’ layout is a little different between WIndows and Linux. Is there an approach to make both exactly same? Thanks

Regards,
Chenxg

Hi @chenxg
We tested it and found the following:
1, ASP.NET Core Web Application, deployed to AWS Elastic Beanstalk.
2, AWS Serverless project, deployed to AWS Lambda.
For 1 and 2, Aspose.Cells for netstandard runs OK.

3, “AWS Lambda Function Project, deployed to AWS Lambda”, it will cause an error:
System.TypeInitializationException: The type initializer for ‘Gdip’ threw an exception. —> System.DllNotFoundException: Unable to load shared library ‘libgdiplus’ or one of its dependencies.

so far, Aspose.Cells for netstandard depend on system.drawing.common, it seems that AWS Lambda doesn’t support it very well,
We have also conducted an investigation and so far have found no solution.
we have a plan to abandon system.drawing.common, but it will need a lot of work to do.

On the issue of font differences, we did find that, in the case of Linux ensuring that the font files are loaded correctly, there are some differences between the generated images and those in windows, which should be the differences between the graphics libraries running across platforms.

You can use the function “Aspose.Cells.FontConfigs.SetFontFolder” to set the font directory, and make sure the font files are in the directory, to ensure that the font is loaded correctly. In this way, the above differences should be minimized.

Hi @chenxg
We released Aspose.Cells version that uses skiasharp, to resolve the problem that “libgdiplus” does not work well in AWS Lambda.
You can refer to the documentation below for the new version.