IText 中文字体解决方案 生成doc文档

IText生成doc文档需要三个包:iTextAsian.jar,iText-rtf-2.1.4.jar,iText-2.1.4.jar

亲测无误,代码如下:

import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.rtf.RtfWriter2;
import org.junit.Test; import java.io.FileOutputStream; /**
* Created with IntelliJ IDEA.
* User: HYY
* Date: 13-8-1
* Time: 下午9:57
* To change this template use File | Settings | File Templates.
*/
public class ChineseTest {
@Test
public void test() throws Exception {
// 创建word文档,并设置纸张的大小
Document document = new Document(PageSize.A4);
//设置存放路径
RtfWriter2.getInstance(document, new FileOutputStream("C:/1.doc"));
document.open(); BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font FontChinese = new Font(bfChinese, 14, Font.NORMAL);
Paragraph paragraph = new Paragraph("IText中文字体解决方案 —— 無幽之路", FontChinese); document.add(paragraph); document.close();
}
}
上一篇:UML model refactoring: a systematic literature review


下一篇:利用Java动态生成 PDF 文档