XhtmlParagraph and TrueType fonts

Fonts, Generate PDF, HTML / CSS

The following code converts XHTML to PDF using the XhtmlParagraph. The HTML specfies Georgia as the font to use using an inline style attribute. The FontPath property of ConversionSettings instructs XhtmlParagraph to use the fonts inside this folder.

Document document = new Document();
Section section = document.Sections.Add();
XhtmlParagraph xhtml = new XhtmlParagraph();

xhtml.Text = File.ReadAllText(@"in.html");
xhtml.Settings = new ConversionSettings { FontPath = @"d:\fonts" };

using (FileStream file = new FileStream("out.pdf", FileMode.Create))

Document in.html looks as follows:

        <p style="font-family: Georgia">Hello world</p>