selectpdf / selectpdf-free-html-to-pdf-converter

Free Html To Pdf Converter for .NET. Asp.Net, C# sample.
13 stars 2 forks source link

Linked Google webfonts not working #27

Open CodeKarstenJ opened 1 year ago

CodeKarstenJ commented 1 year ago

My application is a .NET 5 Web API that will run as an App Service on Microsoft Azure

Everything works fine except the custom font I am trying to use I am trying to link a font from google in HTML and then convert this to pdf

The HTML head has this tag inside <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Muli" />

And the CSS looks like this

html,
body {
    font-family: Muli;
}

I have also tried using @font-face like so:

@font-face {
  font-family: 'Muli';
  src: url(https://fonts.gstatic.com/s/muli/v28/7Aulp_0qiz-aVz7u3PJLcUMYOFnOkEk40eiNxw.woff2) format('woff2');
}

I have also tried downloading the TTF file for the font and adding it to a blob storage container in Azure, and using the link to that file in @font-face

I have also tried to increase the Converter.Options.MinPageLoadTime to 2 seconds

Every single one of these options work on my local machine, but not in Azure

Are there any other options that I might have overlooked, or is there nothing else I can do?

uggeh commented 2 months ago

I've got the same problem. Did you ever find any solution to this?

CodeKarstenJ commented 2 months ago

I've got the same problem. Did you ever find any solution to this?

Hi there, I'm sorry, unfortunately I haven't found a solution to it yet.

It is quite unfortunate because we have a design language with a specific font in mind for text.

Just to add to my original question that I failed to mention is that the App service runs in a Windows environment on Azure because the System.Drawing namespace, which is very important to this NuGet package, only works on Windows

I'll see if I can tinker some more with the TTF file idea and see if it is in a different directory on the azure environment and update the code to see if it works

uggeh commented 2 months ago

Ok, I'm also using windows app service environment in Azure.

I've tried including the TTF file in the release-package and referenced it with font-face src (html file in same folder as TTF file), but it didn't work. @font-face { font-family: "Pathway Gothic One"; src: url("PathwayGothicOne-Regular.ttf"); } .poi { font-family: "Pathway Gothic One"; }

This guy has also done lots of testing with both SelectPdf and also DinkToPdf but came to the following conclusion: image He ended up with running SelectPdf in a VM in Azure instead, which worked. But I would rather not run it in a VM since you loose lots of the good stuff with Azure (easy logging, easy configuration, easy scaling...)

Another possible solution would be to set up the whole deployment package as a container, deploy it to a container registry in Azure and point the Azure App Service to run the container. But it feels overkill to change the whole deployment setup just to get a font working 😄

It feels like there must be a way to get the lib to load and use a font from file, without the font being installed on the OS.

selectpdf commented 2 months ago

I am afraid web fonts not loading on Azure web apps services is a limitation of Azure and there is no work around it at the current time.

CodeKarstenJ commented 2 months ago

Ok, I'm also using windows app service environment in Azure.

I've tried including the TTF file in the release-package and referenced it with font-face src (html file in same folder as TTF file), but it didn't work. @font-face { font-family: "Pathway Gothic One"; src: url("PathwayGothicOne-Regular.ttf"); } .poi { font-family: "Pathway Gothic One"; }

This guy has also done lots of testing with both SelectPdf and also DinkToPdf but came to the following conclusion: image He ended up with running SelectPdf in a VM in Azure instead, which worked. But I would rather not run it in a VM since you loose lots of the good stuff with Azure (easy logging, easy configuration, easy scaling...)

Another possible solution would be to set up the whole deployment package as a container, deploy it to a container registry in Azure and point the Azure App Service to run the container. But it feels overkill to change the whole deployment setup just to get a font working 😄

It feels like there must be a way to get the lib to load and use a font from file, without the font being installed on the OS.

By container, do you mean to run it in a docker container built with windows environment?

Maybe it could work?? But as @selectpdf just mentioned that it is a limitation on Azure, then I personally don't feel that it is worth my time trying to find a workaround for it.

I use docker for all of my web projects and all of these containers are run in Azure inside Linux environments, because it is less costly than Windows, and a few of them require dynamic pdf's to be generated and downloaded.

Because the package doesn't work in Linux, I have opted to create one web application with the sole purpose of generating these pdf's, and it runs in a Windows environment App Service

CodeKarstenJ commented 2 months ago

I am afraid web fonts not loading on Azure web apps services is a limitation of Azure and there is no work around it at the current time.

Could it be perhaps that Azure blocks the download of the font in the <link> tag? I'm just guessing here