Using Fonts in System with iTextSharp
1st you need to register the font and then just retrieve it from the FontFactory (and don't create it every time):
public static iTextSharp.text.Font GetTahoma()
{
var fontName = "Tahoma";
if (!FontFactory.IsRegistered(fontName))
{
var fontPath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\tahoma.ttf";
FontFactory.Register(fontPath,fontName);
}
return FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
}
I ended up combining the 2 answers here into this method:
public static Font GetFont(string fontName, string filename)
{
if (!FontFactory.IsRegistered(fontName))
{
var fontPath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\" + filename;
FontFactory.Register(fontPath);
}
return FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
}
Which I then use in my code like so:
writer.DirectContent.SetFontAndSize(GetFont("Franklin Gothic Medium Cond", "FRAMDCN.TTF").BaseFont, 24f);
On Windows you can find out the font's file name from the font's property sheet:
I also found that you have to use the font's exact name on the Details tab: