3

I am trying to publish and use a font on my Windows Azure web app.

The font file is bahnschrift.ttf. I can see the file at the correct location on Azure so I’m sure it was published correctly.

I want to use the font to draw text onto an image.

This code using PrivateFontCollection works in the Visual Studio debugger on my Windows 10 machine. It does not work when published to Azure.

I also tried setting the MIME type in my web.config file but that didn’t change anything.

private static FontFamily GetFontBahnschrift() {

    PrivateFontCollection fonts = new PrivateFontCollection();

   string file = HttpContext.Current.Server.MapPath("~/img/bahnschrift.ttf");
        fonts.AddFontFile(file);

    FontFamily fontBahnschrift = fonts.Families.First(p => 
p.Name.Equals("Bahnschrift Bold", 
StringComparison.CurrentCultureIgnoreCase));

    return fontBahnschrift;
}


<system.webServer>
  <staticContent>
    <remove fileExtension=".ttf" />
    <mimeMap fileExtension=".ttf" mimeType="font/ttf" />
  </staticContent>
</system.webServer>

I want to be able to use the TTF font on Windows Azure.

Hank Tuff
  • 185
  • 5
  • 12

1 Answers1

1

Known issue for all PDF generators based on wkhtmltopdf or phantomjs: custom fonts are not rendered (system-installed font is used instead) because of sandbox GDI API limitations that present even in VM-based Azure Apps plans (Basic or higher).

Refer this document for more details.

You may use Windows Containers in App Service to apply custom fonts: https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-windows-containers-custom-fonts

Kindly checkout this similar feedback post here.

AjayKumar
  • 2,812
  • 1
  • 9
  • 28