Products
TallPDF.NET 4.0
Created
10/3/2016
Tags
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();
section.Paragraphs.Add(xhtml);

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

using (FileStream file = new FileStream("out.pdf", FileMode.Create))
{
   document.Write(file);
}

Document in.html looks as follows:

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