首页 > 代码库 > Font 'C:\WINDOWS\FONTS\msyh.ttc' with 'Identity-H' is not recognized

Font 'C:\WINDOWS\FONTS\msyh.ttc' with 'Identity-H' is not recognized

在生成PDF使用windows自带字体雅黑的时候不停的报“Font ‘C:\WINDOWS\FONTS\msyh.ttc‘ with ‘Identity-H‘ is not recognized”的错误

解决方案

static BaseFont yaHei = BaseFont.CreateFont("c://windows//fonts//msyh.ttc", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);//微软雅黑

改为

static BaseFont yaHei = BaseFont.CreateFont("c://windows//fonts//msyh.ttc,0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);//微软雅黑

在字体路径的后面加了一个“,0”解决了,虽然不知道为什么,但是猜测这个是字体组有关,因为雅黑有三种,常规、加粗、极细

 

Font 'C:\WINDOWS\FONTS\msyh.ttc' with 'Identity-H' is not recognized