I want to apply Trade gothic font to my pdf text using PDFsharp, I have installed the font and use below line of code to apply
XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
// var options = new XPdfFontOptions(PdfFontEmbedding.Always);
XFont font = new XFont("TRADE GOTHIC BOLD CONDENSED NO. 20", 20, XFontStyle.Bold, options);
But it does not work!!. Also I wanted to know in production I'm using Windows server 2008, is there a way I can dynamically add this font in production server even it is not there?
As suggested I followed the pdfsharp forum , this is my sample code
XPrivateFontCollection privateFontCollection = XPrivateFontCollection.Global;
// Uri fontUri = new Uri(MappedApplicationPath + "Fonts\\trade-gothic-no-20-condensed-bold-1361518746.ttf");
Uri fontUri = new Uri("C:\\inetpub\\wwwroot\\wss\\VirtualDirectories\\80\\Fonts\\trade-gothic-no-20-condensed-bold-1361518746.ttf");
LoadPrivateFont(privateFontCollection, fontUri, "./#TradeGothicNo.20-Condensed");
I tried all possible combination of path and file name , the name as mentioned in .ttf file but still getting exception . I have a sharepoint Visual webpart, and on page load event of that webpart m writing this code..
This is load method
protected void LoadPrivateFont(PdfSharp.Drawing.XPrivateFontCollection privateFontCollection, Uri fontUri, string sFontFamilyname)
{
try
{
privateFontCollection.Add(fontUri, sFontFamilyname);
}
catch
{
}
}
I have followed this post http://forum.pdfsharp.net/viewtopic.php?f=2&t=1880
Thanks