Error when exporting XLSX to PDF using .NET Aspose.Cells in docker container

Hi,
I am evaluating Aspose.Cells .NET when I get a similar issues that customer get in this thread Aspose.cells: saving excel to pdf don't work on docker container.

image.png (33.1 KB)

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
Aspose.Cells.CellsException: The type initializer for ‘’ threw an exception.
at Aspose.Cells.Workbook.Save(Stream stream, SaveOptions saveOptions)
at WorkbookManager.SaveWorkbookAsPdf(String templateName) in /workspace/temp_poc_aspoce_cells/ExcelAPI/Program.cs:line 96
at Program.<>c.<<$>b__0_2>d.MoveNext() in /workspace/temp_poc_aspoce_cells/ExcelAPI/Program.cs:line 33
— End of stack trace from previous location —
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

I tried what fixed it for the customer by modifying my docker file to this:

FROM gitpod/workspace-dotnet:latest

RUN sudo apt-get install -y libfontconfig1

RUN sudo apt-get install -y libgdiplus
RUN cd /usr/lib && sudo ln -s libgdiplus.so gdiplus.dll

RUN sudo apt-get install -y --no-install-recommends libc6-dev

RUN sudo apt-get install -y cabextract xfonts-utils \
  && sudo wget http://ftp.us.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.7_all.deb \
  && sudo dpkg -i ttf-mscorefonts-installer_3.7_all.deb \
  && sudo fc-cache -f -v

I am using target net7.0 and Aspose.Cells/23.9.0

I also created a runtimeconfig.template.json that I put in the root directory, the application directory and the obj sub folder of the application directory to be sure it’s being used.

{
“configProperties”: {
“System.Drawing.EnableUnixSupport”: true
}
}

I am making sure that the Excel is properly exported to XLSX before I try to export it to PDF.

_workbook = new Workbook($“…/Templates/{templateName}.xlsx”);
_workbook.Save($“…/Output/{templateName}.xlsx”, SaveFormat.Xlsx);
_workbook.Save($“…/Output/{templateName}.pdf”, new PdfSaveOptions());

The XLSX is exported correctly.

Nothing I tried had fixed the issue. What should I do?

@karl.sjostrand,

Aspose.Cells now also provides separate .NET6.0 and .NET7.0 libraries (in the release archive) that use SkiaSharp as the graphics library, as recommended in official statement of Microsoft. For more details about using Aspose.Cells with NET6, please see the document on how to use and run Aspose.Cells for .NET6.0. It will also work for .NET7.0

Please try using our latest version/fix: Aspose.Cells for .NET v23.9 (Releases | NuGet).

I solved it by installing this package.

dotnet add package SkiaSharp.NativeAssets.Linux

@karl.sjostrand,

Good to know that your issue is sorted out by installing/using the suggested library. Feel free to contact us any time if you have further queries or issue, we will be happy to assist you soon.