3

I am using Google font "Open Sans,sans-serif" in CSS for my web page.I am using evo pdf to generate PDF. In this dynamically creating header and footer using TextElement.

My problem is in c# fontfamily there is no such Google font.How can I get "Open Sans,sans-serif" in c# fontfamily?

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);
Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
James
  • 301
  • 2
  • 16

2 Answers2

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"), 

Isn't this what you are looking for : evo guide to using fonts

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111
Abhay Dhar
  • 131
  • 11
0

You can actually use fonts which are not installed on the local system. You just need the .ttf or .otf file and load the fonts from file like this:

// 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);

You can also see the entire demo with more code samples for text and fonts handling. You have to select the 'Sample Code' tab in that page.

EvoPdf
  • 523
  • 3
  • 9