zoukankan      html  css  js  c++  java
  • 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();
        }
    }
  • 相关阅读:
    tips for Flask
    REST
    数据结构与算法分析 in C语言
    大学环境对大学生学习心态的影响
    Qpython_文本读写_工作目录
    The Zen of Python
    SQL SERVER数据库中DDL语句
    sql server创建序列sequence
    macbook 安装redis流程及问题总结
    mac系统chrome浏览器快捷键
  • 原文地址:https://www.cnblogs.com/wuyou/p/3236675.html
Copyright © 2011-2022 走看看