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();
  • 相关阅读:
    安装和使用 PyInstaller 遇到的问题
    Mininet 系列实验(七)
    Mininet 系列实验(六)
    Mininet 系列实验(五)
    Mininet 系列实验(三)
    Mininet 系列实验(一)
    Linux进程间通信(消息队列/信号量+共享内存)
    bugku 输入密码查看flag
    bugku 头等舱
    bugku 你必须让他停下
  • 原文地址:https://www.cnblogs.com/MissRabbit/p/6140969.html
Copyright © 2011-2022 走看看