PDF无法导出中文

时间:2024-10-09 14:32:29

font/SIMSUN.TTC' with 'Identity-H' is not recognized.

查看BaseFont源码发现".ttc,"

改为"SIMSUN.TTC,a"提示数字转换异常

改为"SIMSUN.TTC,11"提示数字索引必须介于0和1之间

改为0或1结果正常

BaseFont baseFont = BaseFont.createFont("/Users/fanshaorong/Desktop/uploadPath/templates/font/SIMSUN.TTC,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

或者改为使用simfang.ttf

BaseFont baseFont = BaseFont.createFont(BASENAME, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            Font font = new Font(baseFont);

……
cell = new PdfPCell(new Paragraph(getFieldName(i), font));