We use a third-party PDF Generator library which requires that you specify the TrueType or Type1 file name when using a font other than the 14 or so that are part of the default PDF standard.
So if I want to use Bitstream Arrus Bold
I have to know to reference arrusb.ttf
.
Short of enumerating all of the files in the font folder and creating a disposable PrivateFontCollection to extract the relationships, is there a way to obtain the underlying font name from font information, i.e. given Courier New, Bold, Italic derive CourBI.ttf
?
I've already looked at the InstalledFontCollection and there's nothing.
If you don't mind poking around in the registry, take a look at
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts
It has pairs like
Name = "Arial (TrueType)"
Data = "arial.ttf"
You can do this the necessary queries like this:
static RegistryKey fontsKey =
Registry.LocalMachine.OpenSubKey(
@"Software\Microsoft\Windows NT\CurrentVersion\Fonts");
static public string GetFontFile(string fontName)
{
return fontsKey.GetValue(fontName, string.Empty) as string;
}
A call to GetFontFile("Arial (TrueType)")
returns "arial.ttf"
You could of course modify the code to append the (TrueType)
portion to the fontName
, or to look through everything returned by fontsKey.GetValueNames()
to find the best match.