Is there an easy way (in .Net) to test if a Font is installed on the current machine?
7 Answers
string fontName = "Consolas";
float fontSize = 12;
using (Font fontTester = new Font(
fontName,
fontSize,
FontStyle.Regular,
GraphicsUnit.Pixel))
{
if (fontTester.Name == fontName)
{
// Font exists
}
else
{
// Font doesn't exist
}
}

- 7,500
- 3
- 31
- 34
How do you get a list of all the installed fonts?
var fontsCollection = new InstalledFontCollection();
foreach (var fontFamily in fontsCollection.Families)
{
if (fontFamily.Name == fontName) {...} \\ check if font is installed
}
See InstalledFontCollection class for details.
-
6This is the most "direct" way to me, other proposed answers look more like workarounds. – Ugur Turan Apr 13 '12 at 07:26
-
1@UgurTuran: Yes, however I wonder about performance? Wouldn't know until you tried, but gut says the others are faster due to the opportunity for has table lookups. – Hans Feb 01 '13 at 19:31
Thanks to Jeff, I have better read the documentation of the Font class:
If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.
The result of this knowledge:
private bool IsFontInstalled(string fontName) {
using (var testFont = new Font(fontName, 8)) {
return 0 == string.Compare(
fontName,
testFont.Name,
StringComparison.InvariantCultureIgnoreCase);
}
}

- 78,642
- 66
- 377
- 442

- 52,015
- 16
- 101
- 139
-
3Evidently this Font constructor assumes FontStyle.Regular ... it only works if the Regular font style is available – jltrem Jul 11 '13 at 14:30
Other answers proposed using Font
creation only work if the FontStyle.Regular
is available. Some fonts, for example Verlag Bold, do not have a regular style. Creation would fail with exception Font 'Verlag Bold' does not support style 'Regular'. You'll need to check for styles that your application will require. A solution follows:
public static bool IsFontInstalled(string fontName)
{
bool installed = IsFontInstalled(fontName, FontStyle.Regular);
if (!installed) { installed = IsFontInstalled(fontName, FontStyle.Bold); }
if (!installed) { installed = IsFontInstalled(fontName, FontStyle.Italic); }
return installed;
}
public static bool IsFontInstalled(string fontName, FontStyle style)
{
bool installed = false;
const float emSize = 8.0f;
try
{
using (var testFont = new Font(fontName, emSize, style))
{
installed = (0 == string.Compare(fontName, testFont.Name, StringComparison.InvariantCultureIgnoreCase));
}
}
catch
{
}
return installed;
}

- 12,124
- 4
- 40
- 50
Here's how I would do it:
private static bool IsFontInstalled(string name)
{
using (InstalledFontCollection fontsCollection = new InstalledFontCollection())
{
return fontsCollection.Families
.Any(x => x.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase));
}
}
One thing to note with this is that the Name
property is not always what you would expect from looking in C:\WINDOWS\Fonts. For example, I have a font installed called "Arabic Typsetting Regular". IsFontInstalled("Arabic Typesetting Regular")
will return false, but IsFontInstalled("Arabic Typesetting")
will return true. ("Arabic Typesetting" is the name of the font in Windows' font preview tool.)
As far as resources go, I ran a test where I called this method several times, and the test finished in only a few milliseconds every time. My machine's a bit overpowered, but unless you'd need to run this query very frequently it seems the performance is very good (and even if you did, that's what caching is for).

- 1,173
- 1
- 10
- 28
Going off of GvS' answer:
private static bool IsFontInstalled(string fontName)
{
using (var testFont = new Font(fontName, 8))
return fontName.Equals(testFont.Name, StringComparison.InvariantCultureIgnoreCase);
}

- 2,230
- 23
- 23
In my case I need to check font filename with extension
ex: verdana.ttf = Verdana Regular, verdanai.ttf = Verdana Italic
using System.IO;
IsFontInstalled("verdana.ttf")
public bool IsFontInstalled(string ContentFontName)
{
return File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), ContentFontName.ToUpper()));
}

- 239
- 4
- 4