日期:2014-05-18  浏览次数:20742 次

iText生成PDF,显示中文问题
问题: 为什么执行到BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);此句就直接例外了呢?
Document document = new Document(PageSize.A4, 5, 5, 5, 5);

try {


PdfWriter.getInstance(document, new FileOutputStream(path
+ filename));
document.open();

BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

Font titleFont = new Font(bfChinese, 10, Font.NORMAL, Color.GREEN);

document.add(new Paragraph("tt", titleFont));
document.close();

} catch (Exception e) {

}

------解决方案--------------------
BaseFont bfChinese = BaseFont.createFont(
"c://WINDOWS//Fonts//simsun.TTC,0", BaseFont.IDENTITY_H,
BaseFont.NOT_EMBEDDED);