Search code examples
asp.netfont-facewkhtmltopdfazure-web-app-servicenreco

custom fonts with wkhtmltopdf wrapper nreco on azure web app


i am converting an html file to an pdf with the .net wrapper "NReco.PdfGenerator" for wkhtmltopdf on an azure web app (running in standard plan) but cannot include custom fonts in my document. The custom fonts are not loaded by the PDF generator or just ignored from it. I've tried different formats for including the font files like link to google fonts css, import from google fonts, relativ local paths, absolute local paths, loading the font file over localhost and font-faces with base64 encoded fonts:

@@font-face {
            font-family: 'testfont';
            src:  url(data:application/x-font-woff;charset=utf-8;base64,...) format('woff');
            font-weight: normal;
            font-style: normal;
        }

using with:

font-family: 'testfont';

@@ because i am using razor views. When saving the generated HTML to file it looks fine and works fine when opening in browser (chrome).

Generating the PDF:

var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
return htmlToPdf.GeneratePdf(html);

I also removed backup fonts from the font-family statement. I've tried different versions from wkhtmltopdf without luck. The generator handels images from localhost fine.

When running the same asp.net app on my windows machine the fonts works fine.

The NReco docs says "avoid usage of custom fonts" (in azure web app enviroment), does this mean there is no chance to get it running? Why are custom fonts not supported? Is there any workaround?

thanks for any help.


Solution

  • This is known issue: Azure Apps hosting environment restricts some GDI APIs and as result wkhtmltopdf cannot load (and render) custom fonts. Only standard fonts that are present on Windows by default could be used (like Arial, Times New Roman etc). You may contact Azure Support on this topic - they could provide more details on the Azure Apps sandbox limitations.