Code:
//Setup for PdfSharp to use custom fonts.
var fontResolver = EzFontResolver.Get;
GlobalFontSettings.FontResolver = fontResolver;
fontResolver.AddFont("Courier New", XFontStyle.Regular, fontPath, true, true);
var fontNames = new List<string>
{
"courier new"
};
foreach (var fontName in fontNames)
{
new XFont(fontName, 20, XFontStyle.Regular);
document.Styles.AddStyle(fontName, "Normal");
var style = document.Styles[fontName];
style.Font = new Font(fontName);
var styleName = fontName;
var para = document.AddSection().AddParagraph("H", styleName);
para.Format.Font.Bold = true;
para = document.AddSection().AddParagraph("H", styleName);
para.Format.Font.Italic = true;
para = document.AddSection().AddParagraph("H", styleName);
para.Format.Font.Bold = true;
para.Format.Font.Italic = true;
}
var pdfRenderer = new PdfDocumentRenderer { Document = document};
pdfRenderer.RenderDocument();
pdfRenderer.PdfDocument.Close();
pdfRenderer.PdfDocument.Dispose();
This should populate the static dictionary.