HTML to PDF Custom fonts

I am converting a html page to a pdf, but I cannot figure out how to load a custom font.

I managed to get the font loaded and working without the html by using FontRepository.OpenFont("D:\\OmnesBold-Roman.ttf") but this doesn't help my html problem.

For example in my html I have

My header

How can I use my custom font path with the html?

Hi Paul,


Thanks for your inquiry. Please note to use any custom font, you need to install it over your system first and if you want to embed the font information into the resultant PDF then please use 'isUnicode=‘true’ property setting. Hopefully it will serve the purpose.


Please feel free to contact us for any further assistance.


Best Regards,

So there is no way to use a font that isn't installed on the system? I want to use a font which is included in my project. I don't want to have to install it on every server I deploy to.

Does something like FontRepository.Sources.Add not help?

Hi Paul,


Thanks for your feedback. Please check following code snippet to reference a true type font from folder path. Hopefully it will serve the purpose. If issue persist then please share your sample html document and font file. So we will test the scenario at our end and will provide you more information.

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();
// Read the contents of HTML file into StreamReader object
StreamReader r = File.OpenText(myDir + “HtmlFont.html”);
//Create text paragraphs containing HTML text
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd());
// enable the property to display HTML contents within their own formatting
text2.IsHtmlTagSupported = true;
text2.TextInfo.IsUnicode = true;

// to use custom true type font
text2.TextInfo.TruetypeFontFileName = “D:/OmnesBold-Roman.ttf”;
text2.TextInfo.FontName = “OmnesBold-Roman”;
//<-- without this line FontName property does not influence HtmlToPdf conversion
text2.UseTextInfoStyle = true;
//Add the text paragraphs containing HTML text to the section
section.Paragraphs.Add(text2);
section.IsLandscape = true;

//Save the pdf document
pdf.SetUnicode();
pdf.Save(myDir + “HtmlPDF.pdf”);

Please feel free to contact us for any further assistance.

Best Regards,