iText 中写Word RTF 文档 中文字体设置
2009-07-23 13:50
337 查看
传统使用iTextAsian.jar中定义的字体
但是这种办法只能时是在亚洲语言包中定义的
2、网上查到的引用windows字体的方式,但度rtf格式不支持,显示的是英文名称的字体
3 经过反复测试,下面这种办法支持word
word中表现如下
写字板中表现如下:
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); com.lowagie.text.Font FontChinese = new com.lowagie.text.Font(bfChinese, 12, com.lowagie.text.Font.NORMAL);
但是这种办法只能时是在亚洲语言包中定义的
2、网上查到的引用windows字体的方式,但度rtf格式不支持,显示的是英文名称的字体
BaseFont.createFont("C:/WINDOWS/Fonts/SIMYOU.TTF", BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED); com.lowagie.text.Font FontChinese = new com.lowagie.text.Font(bfChinese, 12, com.lowagie.text.Font.NORMAL)
3 经过反复测试,下面这种办法支持word
// step 1: 定义 Document document = new Document(); try { // step 2: // 建立一个rtf文档 RtfWriter2.getInstance(document, new FileOutputStream(filePath + file)); // step 3: we open the document document.open(); //设置字体 字体名称是中文的,在中间的中文字符前后加空格, //这种写法是实验多次后的结果,直接写在word中体现为 "华?行?楷",这种写法感觉很怪异。 //在写字板中打开和word中打开不一样,见图 RtfFont font = new RtfFont("华 文 行 楷", 36, Font.BOLD, Color.BLACK); String text = "这是中文字体测试!this is a test"; document.add(new Paragraph(text, font)); System.out.println(font.getFamilyname()); } catch(DocumentException de) { System.err.println(de.getMessage()); } catch(IOException ioe) { System.err.println(ioe.getMessage()); }finally{ document.close(); } // step 5: we close the document
word中表现如下
写字板中表现如下:
相关文章推荐
- iText 中写Word RTF 文档 中文字体设置 [转]
- java-pdf-itext7、itextpdf 生成pdf 文档,使用pdf模板生成(支持中文字体)
- IText 中文字体解决方案 生成doc文档
- Itext设置导出word文件的字体
- Java导出Word文档(可设置字体)
- Matlab中文字体乱码设置-----help文档
- java-pdf-itext 生成pdf 文档(支持中文字体)
- word文档分别批量修改中文与英文字体大小字号等格式
- Android TextView中文字通过SpannableString来设置超链接、颜色、字体等属性
- word 如何快速给字体上色---快捷键设置 && 删除多余回车符的技巧
- Android用itext生成含中文的PDF文档
- android: 设置中文字体效果的一些方法
- 【Scikit-Learn 中文文档】机器学习: scikit-learn 中的设置以及预估对象 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】机器学习: scikit-learn 中的设置以及预估对象 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- Ubuntu 中文字体设置备忘
- Mac OS X 10.9下MacTeX 2013中文字体设置
- word文档中字体大小和像素对照关系
- 【Scikit-Learn 中文文档】机器学习: scikit-learn 中的设置以及预估对象 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- ubuntu中中文默认字体的设置
- 解决了 source insight 设置为 微软雅黑后 中文字体重影