请教请教
各位,使用ItextPdf 生成pdf文件,在使用中文字体情况下,如果通过main方法调用生成pdf方法是没有问题的,但是在项目中通过页面发起请求,就会报错。 Font ‘STSong-Light’ with ‘UniGB-UCS2-H’ is not recognized. 困扰一天多了,求指教。。。。谢谢了
所用jar
System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
FileOutputStream out = new FileOutputStream(file);// 输出流
PdfReader reader = new PdfReader(templatePath);// 读取pdf模板
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader, bos);
AcroFields form = stamper.getAcroFields();
//使用中文字体
//BaseFont bf = BaseFont.createFont(SystemConfig.ROOT+"/fonts/simhei.ttf",BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.EMBEDDED);
ArrayList<BaseFont> fontList = new ArrayList<BaseFont>();
fontList.add(bf);
form.addSubstitutionFont(bf);
使用中文字体那一句代码,BaseFont bf = BaseFont.createFont(“STSong-Light”, “UniGB-UCS2-H”,BaseFont.EMBEDDED);
一直报错 Font ‘STSong-Light’ with ‘UniGB-UCS2-H’ is not recognized.。