2015-02-10 98 views
3

我在CSS中爲我的網頁使用Google字體「Open Sans,sans-serif」。​​我使用evo pdf生成PDF。在這個使用TextElement動態創建頁眉和頁腳。c#中的FontFamily問題#

我的問題是在c#fontfamily沒有這樣的谷歌字體。我怎樣才能在C#fontfamily中獲得「Open Sans,sans-serif」?

TextElement footerText = new TextElement(0, 15, "Page &p; of &P; ", 
       new System.Drawing.Font(this.OpenSans,12, FontStyle.Regular, GraphicsUnit.Pixel)); 
footerText.TextAlign = HorizontalTextAlign.Right; 
footerText.ForeColor = Color.Black; 
footerText.EmbedSysFont = true; 
htmlToPdfConverter.PdfFooterOptions.AddElement(footerText); 

回答

0
TextElement footerText = new TextElement(0, pdfConverter.PdfFooterOptions.FooterHeight - 15, 
      "This is page &p; of &P; ", 
      new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"), 

這不是你在找什麼:evo guide to using fonts

+0

詹姆斯特別想要一個Google字體,而不是標準的Times New Roman。 – 2015-02-11 11:06:51

+0

是的,我需要谷歌字體在C# – James 2015-02-13 06:14:30

0

您實際上可以使用未在本地系統上安裝的字體。你只需要在.TTF或雜項文件文件,並從文件加載的字體是這樣的:

// Embed a True Type font from a local file in PDF document 
PdfFont localTrueTypeFont = pdfDocument.AddFont(@"DemoAppFiles\Input\Fonts\TrueType.ttf"); 

// Add a text element using the local True Type font to PDF document 
TextElement localFontTtfTextElement = new TextElement(xLocation, yLocation, "This text uses a True Type Font loaded from a local file", localTrueTypeFont); 
addTextResult = pdfPage.AddElement(localFontTtfTextElement); 

你也可以看到整個演示與more code samples for text and fonts handling。您必須在該頁面中選擇「示例代碼」選項卡。