iTextPDF

一、中文输出问题:

  1. 需要导入2个包:

    iText.jar

    iTextAsian.jar

  2. 实现代码如下

private static Paragraph getChinese(String str,int c,int ifBold) throws DocumentException, IOException{  
/*        
    BaseFont bfChinese = null;
        try{
            bfChinese = BaseFont.createFont("C:/windows/fonts/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);  //系统默认中文(宋体)
        }catch(Exception e){
            e.printStackTrace();
            bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); 
        }
*/
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); 
        Font FontChinese = new Font(bfChinese, c, ifBold); // 设置为中文                
        Paragraph pragraph=new Paragraph(str, FontChinese);     
        return pragraph;
}

  3. 具体编写,可参考:

    http://www.cnblogs.com/crazyjava/p/3199936.html

    http://blog.csdn.net/mr_linjw/article/details/48369769

    http://blog.csdn.net/fuchen_pxf/article/details/17076773

    http://blog.chinaunix.net/uid-122937-id-3052666.html

二、document 设置

//    Document document = new Document(PageSize.A4, 30f, 30f, 30f, 30f);//设置页大小A4,也边距(左右,上下)
      Document document = new Document();
posted @ 2016-12-07 14:04  ☀Beans✡✌  阅读(273)  评论(0编辑  收藏  举报