We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

HTML font and external image support

I’m trying to use the HTML.Net package to convert Html content to PDF formatted output. I have below issues.

  1. Fonts are not getting resolved properly, It always seems to use the first font it find in the folder
  2. Images are not getting added through urls. the external image urls does not get added to the output. In the real scenario I also want to add a bearer token to the image request, to do that i have added a MessageHandler. Even with a public image, still it does not get added to the output.
    we are doing a POC with this to identify whether this product is a suitable option. please share if the code needs to be improved to HtmlToPdfConverter.zip (1.5 KB)
    fix this. I have attached the sample class files.


The code snippet seems fine. However, can you please also share the sample HTML for our reference so that we can test the scenario in our environment and address it accordingly?

I have attached a sample , in there the image src which has a url worked, now the issue is with images which require bearer taken. i have not added the original url there due to privacy. but if you try to add a img url which require a bearer token and add the authorization header and the original token from the ContentAuthMessageHandler class, still the image want appear due unauthorized error. in my instance i logged the request and checked the generated token and it was valid.
Also if I add a stylesheet which would contain below style , still the correct font will not get picked up on conversion.
@media print {

font-family: OpenSans;
color: #707070; 
font-size: 16px;

}sample-withimage.zip (1.4 KB)


We have logged an investigation ticket as HTMLNET-3309 in our issue tracking system to further analyze this case. We will look into its details and let you know as soon as the ticket is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

1 Like


Message handlers are executed in order of their registration. So in order to specify custom request headers, which will be used by all the other message handlers, you should insert your message handler into the beginning of message handlers collection.

var network = configuration.GetService<Aspose.Html.Services.INetworkService>();
network.MessageHandlers.Insert(0, new ContentAuthMessageHandler());

We were not able to reproduce this problem. The provided HTML document contains such font family definition:

    font-family: sans-serif;

“sans-serif” is a generic font family which is usually resolved as “Arial” font family. And if we specify custom font folder which contain “Arial” and “Times New Roman” fonts, the text inside the table is rendered using “Arial”, as it should be. In order to reproduce this issue we need to know what fonts are present in the “Fonts” folder and what font is expected to be used.