我们使用第三方的PDF生成器库,它要求您在使用非默认PDF标准的14左右的字体时指定TrueType或Type1文件名。
所以如果我想使用Bitstream Arrus Bold
我必须知道引用arrusb.ttf
。
通过枚举字体文件夹中的所有文件并创build一次性PrivateFontCollection来提取关系,有没有一种方法可以从字体信息中获取底层字体名称,即给定Courier New,Bold,Italic派生CourBI.ttf
?
我已经看了InstalledFontCollection,没有什么。
如果你不介意在注册表中查看,请看看
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts
它有双
Name = "Arial (TrueType)" Data = "arial.ttf"
你可以这样做这样的必要的查询:
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; }
调用GetFontFile("Arial (TrueType)")
将返回"arial.ttf"
您当然可以修改代码以将(TrueType)
部分追加到fontName
,或者查看fontsKey.GetValueNames()
返回的所有内容以找到最佳匹配。