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

假装没事ソ 提交于 2020-04-13 06:49:47

问题


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?


回答1:


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.




回答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




回答3:


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

https://docs.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://docs.microsoft.com/en-us/azure/app-service/app-service-web-get-started-windows-container




回答4:


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>


来源:https://stackoverflow.com/questions/38858224/is-it-possible-to-install-fonts-on-an-azure-app-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!