Lets say there is a .ttf (True Type Font) file. You can install it on windows with a click. The real name of the font is not the text that is before the .tff (lets say SuperFont.ttf => so the name is not "SuperFont" - it could be, but mostly not). I would like to read the .tff (somehow?) and get the name (without installing the font) of the font. Any ideas?
Asked
Active
Viewed 1.5k times
2 Answers
26
You'll need to add the font to a private collection (PrivateFontCollection
), then request the FontFamily
instance and get its Name
property.
Like this:
PrivateFontCollection fontCol = new PrivateFontCollection();
fontCol.AddFontFile(@"PATH TO FONT");
Console.WriteLine(fontCol.Families[0].Name);
You'll need the namespaces:
using System.Drawing;
using System.Drawing.Text;
MSDN: PrivateFontCollection, FontFamily

Matt Razza
- 3,524
- 2
- 25
- 29
-
1_(without installing the font)_ – H H Aug 09 '12 at 14:17
-
4This doesn't install the font. Although MSDN uses the term "install" they're using it lightly. "`This is a temporary font install that does not affect the system-installed collection.`" Install here basically means "loaded". – Matt Razza Aug 09 '12 at 14:18
-
1This gets the font family name (e.g. "Open Sans"), but not the full name with the style. For example, every .ttf file for open sans will have the name "Open Sans", not "Open Sans Italic" or "Open Sans Bold". – Triynko Dec 17 '15 at 20:23
3
Here is the another code to extract fontname without using System.Drawing dll
foreach (FontFamily fontFamily in Fonts.GetFontFamilies("file:///D:/MyFonts/"))
{
string name = fontFamily .ToString().Split('#')[fontFamily .ToString().Split('#').Count() - 1];
}

Amrit Pal Singh
- 73
- 6