How to set default font of PDF when converting from HTML

When we use the Aspose HTML to PDF converter, the result of the PDF is in Times New Roman.

We would like to set the default font to Arial if no font type is included in the HTML. How can we do this?

@gerson77

I have observed your requirements. Can you please visit this article Set Default Font. This will help you to achieve your requirements. Please share feedback with us if there is still an issue.

Thank you for your answer.

The issue is not whether the font is avaible on the computer on which the PDF is generated, the issue is to change the default font when it’s not set in the HTML code.

The solution I found is as follows:

            using (var document = new HTMLDocument(htmlString, "."))
            {
                var bodyStyle = document.Body.Style;
                if (string.IsNullOrEmpty(bodyStyle.FontFamily))
                {
                    bodyStyle.FontFamily = FontFamily.GenericSansSerif.Name;
                }

// etc.
}

However, I wonder if this is the best solution.

@gerson77,

Can you please confirm if you checked and tested this code on your end and achieve your desired results.

@Adnan.Ahmad
It works, but it sets a font style attribute on the body tag. I don’t think this is the best solution.

@gerson77,

Can you please share what is your requirements so that we may further investigate either it is possible or not.