zoukankan      html  css  js  c++  java
  • 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();
  • 相关阅读:
    Protocol https not supported or disabled in libcurl
    初学require.js
    HTML中的IE条件注释
    前端,我为什么不要你
    敲点JavaScript代码
    小白科普之JavaScript的函数
    小白科普之JavaScript的BOM模型
    小白科普之JavaScript的JSON
    小白科普之JavaScript的数组
    document.documentElement和document.body的区别
  • 原文地址:https://www.cnblogs.com/MissRabbit/p/6140969.html
Copyright © 2011-2022 走看看