2015-02-10 97 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。您必须在该页面中选择“示例代码”选项卡。