Is it possible to install fonts on an Azure App Service?
Asked Answered
S

4

6

We are using MigraDoc/PDFsharp GDI+ which depends on having fonts installed to the system in order to render. We have tried embedding the fonts but the GDI+ version of MigraDoc does not seem to support this.

When trying to move this component to an Azure App Service, it cannot find the fonts. Is there a way to "install" the fonts locally to the App Service so that they would be visible to GDI?

Skirmish answered 9/8, 2016 at 18:44 Comment(1)
PDFsharp does not depend on having fonts installed to the system, but font support has changed between version 1.32 and version 1.50. Using XPrivateFontCollection should work with version 1.32. I'd use a WPF build of version 1.50 beta 3 or newer as explained in my answer.Distracted
A
0

As I know, Components rely on GDI API may not work on Azure Web APP. We could find this known issue at: https://social.msdn.microsoft.com/Forums/en-US/6ed5c738-390a-4ca7-81d0-370124a4fc88/azure-websites-faq?forum=windowsazurewebsitespreview. At currently, please try to use Azure Web role or Azure VM instead. Please also vote this idea on Azure feedback forum.

Ankylostomiasis answered 10/8, 2016 at 7:22 Comment(0)
D
2

MigraDoc uses PDFsharp to generate PDF files and PDFsharp can use fonts from embedded resources or from files read by the application.

I would use the WPF build of PDFsharp/MigraDoc 1.50 or later and use the IFontResolver interface.

You can use the generic EZFontResolver implementation if that suits your needs:
http://forum.pdfsharp.net/viewtopic.php?f=8&t=3244

Distracted answered 10/8, 2016 at 8:30 Comment(4)
Unfortunately we can't use GDI in Azure Web Apps as the answer showed. However, we rely on GDI because it is around 40% faster for our generation than WPF. Do you know of this performance difference and if there's anything we can do to mitigate? Performance is our top priority due to the number of PDFs we generate.Skirmish
Does "around 40% faster" apply to version 1.50 beta 3b or did you make the test with version 1.32 or earlier? If you would supply an MCVE (using version 1.50 beta 3b) for a test case where GDI+ is around 40% faster than WPF then we can have a look where this difference comes from. stackoverflow.com/help/mcveDistracted
Is there a nuget package for 1.50? I was only able to find pdfsharp 1.50 without migradoc included.Astrogation
There are NuGet packages that include MigraDoc. The WPF package: nuget.org/packages/PDFsharp-MigraDoc-WPF/1.50.4000-beta3b Tick "Include prerelease" in Visual Studio.Distracted
S
2

You can use a Windows Container on App Service for installing custom fonts. Here is how:

https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-windows-containers-custom-fonts

For getting started with Windows Containers on App Service:

https://learn.microsoft.com/en-us/azure/app-service/app-service-web-get-started-windows-container

Surrounding answered 24/1, 2020 at 17:51 Comment(0)
G
1

A little late to this - but better late than never!

I have found out that this is actually quite easy - and we all know how!

Add a web.config to the WWWROOT of the app service add the following

You probably don't need to have the < customHeaders > part unless you want CORS

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <directoryBrowse enabled="false" />
        <httpProtocol>
            <customHeaders>
                <add name="Access-Control-Allow-Origin" value="*" />
            </customHeaders>
        </httpProtocol>
        <staticContent>
            <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
            <mimeMap fileExtension=".ttf" mimeType="application/octet-stream" />
            <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
            <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
            <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
        </staticContent>
    </system.webServer>
</configuration>
Gentlemanly answered 13/2, 2020 at 15:12 Comment(5)
I haven't tried this on PDF activities - theoretically it is the sameGentlemanly
Will this work on ASP.NET Core too? Since the configuration files are in JSON format in ASP.NET Core.Stercoricolous
@AbhilabDas The web.config file is still xml file, so yes it will work.Escobedo
Didn't work for me. Where in the web.config is the path to the custom font that needs to be installed?Freeboard
Hi @uggeh, Can you please help, how to specify path for the custom fonts in Azure app service ?Broadloom
A
0

As I know, Components rely on GDI API may not work on Azure Web APP. We could find this known issue at: https://social.msdn.microsoft.com/Forums/en-US/6ed5c738-390a-4ca7-81d0-370124a4fc88/azure-websites-faq?forum=windowsazurewebsitespreview. At currently, please try to use Azure Web role or Azure VM instead. Please also vote this idea on Azure feedback forum.

Ankylostomiasis answered 10/8, 2016 at 7:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.