Reputation: 572
I'm having troubles adding font-family to a predefined HTML structure with content in itextsharp. Whatever I do, it just keep going to the font "Arial".
I can add font-color without trouble.
This is what I'm using:
var style = new StyleSheet();
style.LoadTagStyle(HtmlTags.TABLE, HtmlTags.COLOR, "#00ff00");
style.LoadTagStyle("body", "font-family", "times new roman");
document.Open();
List<IElement> sr = HTMLWorker.ParseToList(new StringReader(html), style);
foreach (IElement element in sr)
{
document.Add(element);
}
document.close();
Any help would be much appreciated.
Upvotes: 1
Views: 6637
Reputation: 9372
The iText[Sharp] HTML/XML parsers only use the standard PDF Type 1 fonts by default. Times New Roman is not one of those fonts, so you have to explicitly register it before calling LoadTagStyle()
:
FontFactory.RegisterDirectories();
or:
FontFactory.Register(FULL_PATH_TO_TIMES_NEW_ROMAN);
RegisterDirectories()
registers all the Windows system fonts, so it will be much slower.
Or you can go the route of using the Type 1 font, without registering extra fonts:
style.LoadTagStyle(HtmlTags.TABLE, HtmlTags.FACE, "times-roman");
Upvotes: 2