一、问题
aspx后台程序使用new Font("黑体",12)进行初始化时,该字体无法使用。更换成“simhei”也无效
winform程序使用没问题。
二、解决办法
将字体文件拷贝到后台,使用绝对路径定位,直接加载字体文件。
string fontpath = System.Web.HttpContext.Current.Server.MapPath("/themes/font/" + ths_fontstyle.Font_name);
if (FileHelper.IsExistFile(fontpath))
{
System.Drawing.Text.PrivateFontCollection privateFonts = new System.Drawing.Text.PrivateFontCollection();
privateFonts.AddFontFile(fontpath);
System.Drawing.Font font = new Font(privateFonts.Families[0], 12, FontStyle.Bold);
//
}
已有 2178 位网友参与,快来吐槽:
发表评论