当前位置: 技术问答>java相关
iText的中文问题,FAQ上的帖子没有了,麻烦……
来源: 互联网 发布时间:2017-05-01
本文导语: 用iText怎样才能显示中文? 多谢先! | //设置字体-返回中文字体 protected Font getChineseFont(int nfontsize, boolean isBold) throws IOException, DocumentException { BaseFont bfChinese; if(isBold){ bfChinese =...
用iText怎样才能显示中文?
多谢先!
多谢先!
|
//设置字体-返回中文字体
protected Font getChineseFont(int nfontsize, boolean isBold) throws IOException, DocumentException {
BaseFont bfChinese;
if(isBold){
bfChinese = BaseFont.createFont("STSong-Light,Bold", "UniGB-UCS2-H", BaseFont.EMBEDDED);
}else{
bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
}
Font FontChinese = new Font(bfChinese, nfontsize, Font.BOLD);
return FontChinese;
}
//转化中文
protected Cell ChangeCell(String str, int nfontsize, boolean isBold) throws IOException, BadElementException, DocumentException {
Phrase ph = ChangeChinese(str,nfontsize,isBold);
Cell cell = new Cell(ph);
//cell.setBorderWidth(3);
return cell;
}
//转化中文
protected Chunk ChangeChunk(String str, int nfontsize, boolean isBold) throws IOException, BadElementException, DocumentException {
Font FontChinese = getChineseFont(nfontsize,isBold);
Chunk chunk = new Chunk(str, FontChinese);
return chunk;
}
//转化中文
protected Phrase ChangeChinese(String str, int nfontsize, boolean isBold) throws IOException, BadElementException, DocumentException {
Font FontChinese = getChineseFont(nfontsize,isBold);
Phrase ph = new Phrase(str, FontChinese);
return ph;
}
返回各种类型,用于文本和表格足够了。
别忘了加入iTextAsian.jar
protected Font getChineseFont(int nfontsize, boolean isBold) throws IOException, DocumentException {
BaseFont bfChinese;
if(isBold){
bfChinese = BaseFont.createFont("STSong-Light,Bold", "UniGB-UCS2-H", BaseFont.EMBEDDED);
}else{
bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
}
Font FontChinese = new Font(bfChinese, nfontsize, Font.BOLD);
return FontChinese;
}
//转化中文
protected Cell ChangeCell(String str, int nfontsize, boolean isBold) throws IOException, BadElementException, DocumentException {
Phrase ph = ChangeChinese(str,nfontsize,isBold);
Cell cell = new Cell(ph);
//cell.setBorderWidth(3);
return cell;
}
//转化中文
protected Chunk ChangeChunk(String str, int nfontsize, boolean isBold) throws IOException, BadElementException, DocumentException {
Font FontChinese = getChineseFont(nfontsize,isBold);
Chunk chunk = new Chunk(str, FontChinese);
return chunk;
}
//转化中文
protected Phrase ChangeChinese(String str, int nfontsize, boolean isBold) throws IOException, BadElementException, DocumentException {
Font FontChinese = getChineseFont(nfontsize,isBold);
Phrase ph = new Phrase(str, FontChinese);
return ph;
}
返回各种类型,用于文本和表格足够了。
别忘了加入iTextAsian.jar
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。