Search code examples
linuxdockerpdf.net-coresyncfusion

Convert XLSX to PDF using Syncfusion .NET Core library in a Linux Docker Container


I am able to do this running the application locally (.net core 3.1 console application). If I run this within a Linux Docker container I get the following error :

{System.ArgumentNullException: Value cannot be null. (Parameter 'fontFile') at Syncfusion.Pdf.Graphics.PdfTrueTypeFont.CreateFontInternal(Stream fontStream, PdfFontStyle style)

What Im doing is editing an existing XLSX file with replacement values for example :

worksheet.Range["C10"].Text = summary.User.Name;

I can save this fine. Next step is converting this to a PDF where it all falls apart. PS I am able to create a new fresh PDF document fine, issues only occur when doing a conversion.

//Convert Excel document into PDF document 
PdfDocument pdfDocument = renderer.ConvertToPDF(worksheet);

It happens whether I am converting a sheet or the entire workbook.

I have changed all text within the excel file to something standard such as Arial but the issue persists.


Solution

  • The fonts weren’t installed in docker container. So, when converting Excel to PDF through Docker exception is raised. We request you to install fonts to container using below code after first line in Docker file to resolve the issue.

    FROM mcr.microsoft.com/dotnet/core/runtime:3.0-buster-slim AS base 
    RUN apt-get update -y && apt-get install libfontconfig -y 
    ENV LANG="en_US.UTF-8"