Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I am using the ClosedXML library in my project and everything works with no issues locally but when I push and publish the app, I receive the following error when I try to access a page that uses the library's functionality.

This is what I get:
ArgumentException: Unable to find font Calibri or fallback font Microsoft Sans Serif. Install missing fonts or specify a different fallback font through 'LoadOptions.DefaultGraphicEngine = new DefaultGraphicEngine("Fallback font name")'. Additional information is available at https://closedxml.readthedocs.io/en/latest/tips/missing-font.html page.


I understand that the font used by the library exists only on windows machines. I followed the link in the error message and I saw what options I have to fix this.

At first, I wanted to choose a different font as mentioned in the link but I couldn't find where I am supposed to copy the following to in my code:
C#
using (var fallbackFontStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Carlito.ttf"))
{
    // Carlito font will be used for everything, since it is the fallback font and no other font was loaded
    LoadOptions.DefaultGraphicEngine = DefaultGraphicEngine.CreateOnlyWithFonts(fallbackFontStream);
}


I didn't find any place with these keywords to replace or something similar to add this line to. So where can I define the fallback font?

What I have tried:

I also have tried to install the calibri font to the host environment by adding the following lines:
Shell
sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list
apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig

This didn't work because I got an error that I didn't know how to solve, this is the error in the logs:
023-11-16 10:36:11  Step 16/25 : RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list
2023-11-16 10:36:11   ---> Running in 5d254a2c2ec7
2023-11-16 10:36:12  Removing intermediate container 5d254a2c2ec7
2023-11-16 10:36:12   ---> 11327f83bdb8
2023-11-16 10:36:12  Step 17/25 : RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig
2023-11-16 10:36:12   ---> Running in f20c530df6fc
2023-11-16 10:36:12  E: Malformed line 5 in source list /etc/apt/sources.list (type)
2023-11-16 10:36:12  E: The list of sources could not be read.
2023-11-16 10:36:12  E: Malformed line 5 in source list /etc/apt/sources.list (type)
2023-11-16 10:36:12  E: The list of sources could not be read.
2023-11-16 10:36:12  E: Malformed line 5 in source list /etc/apt/sources.list (type)
2023-11-16 10:36:12  E: The list of sources could not be read.
2023-11-16 10:36:12  The command '/bin/sh -c apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig' returned a non-zero code: 100


Can someone help me in fixing this issue, either the 1st or the 2nd problem, much appreciated.
Posted

1 solution

Quote - "
Quote:
ArgumentException: Unable to find font Calibri or fallback font Microsoft Sans Serif. Install missing fonts or specify a different fallback font through 'LoadOptions.DefaultGraphicEngine = new DefaultGraphicEngine("Fallback font name")'. Additional information is available at Missing font — ClosedXML 0.102.0 documentation[^] page.


This tells you exactly what you need to do to rectify the issue...
 
Share this answer
 
v2
Comments
Maciej Los 17-Nov-23 9:45am    
5ed!
Andre Oosthuizen 17-Nov-23 12:56pm    
Whoop whoop Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900