/**
     * 创建(table)PDF,处理cell 跨页处理
     * @param savePath(需要保存的pdf路径)
     * @param pmbs (数据库查询的数据)
     * @return

  *http://www.cnblogs.com/qgc88/
     */
    private String createPDFTable(String savePath, LinkedList<ProjectManageBase> pmbs){
        try{
        Document document = new Document();
       // String separator = System.getProperties().getProperty("file.separator");
        FileOutputStream out = new FileOutputStream(savePath);
       
        PdfWriter.getInstance(document, out);
        document.open();

PdfPTable table = new PdfPTable(7);
       table.setWidthPercentage(100);
       
       table.getDefaultCell().setPaddingLeft(1);
       table.getDefaultCell().setPaddingRight(1);
       table.getDefaultCell().setPaddingTop(2);
       table.getDefaultCell().setPaddingBottom(2);
       table.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);
      // cell 跨页处理:
       table.setSplitLate(false);
       table.setSplitRows(true);
       PdfPCell cell = new PdfPCell();
       
       cell.setColspan(7);
       cell.setUseAscender(true);
       cell.setHorizontalAlignment(Element.ALIGN_CENTER);
       cell.setVerticalAlignment(Element.ALIGN_TOP);
      // 标题居中处理:

BaseFont fontChinese = null;
    try {
        fontChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",
                BaseFont.NOT_EMBEDDED);// 设置中文字体
    } catch (Exception e) {
        e.printStackTrace();
    }
      Font chinese = new Font(fontChinese, 18, Font.BOLD);
       Paragraph title = new Paragraph("组评审结果清单", chinese);
       title.setAlignment(Element.ALIGN_CENTER);
       cell.addElement(title);
       cell.setBorderWidth(0);
       table.addCell(cell);
       
       //列的标题
       Font chinese_cellTitle = new Font(fontChinese, 12, Font.BOLD);
       for (int k = 0; k < 7; k++) {
           String celCount="";
           if(k==0){
               celCount="申报项目";
           }else if(k==1){
               celCount="申报单位";
           }else if(k==2){
               celCount="申报经费\n(万元)";
           }else if(k==3){
               celCount="综合评估\n分数";
           }else if(k==4){
               celCount="综合评估\n名次";
           }else if(k==5){
               celCount="立项等级";
           }else if(k==6){
               celCount="建议经费\n(万元)";
           }
           
           Paragraph count = new Paragraph(celCount, chinese_cellTitle);//支持中文
           count.setAlignment(Element.ALIGN_CENTER);
           cell.setPhrase(count);
           //cell.addElement(count)
           table.addCell(count);
       }
       
       Font chinese2 = new Font(fontChinese, 12, Font.NORMAL);
           for (int j = 0; j <pmbs.size(); j++) {//数据(List)
               for (int k = 0; k < 7; k++) {//内容的列
                   String celCount="";
                   if(k==0){
                       celCount=pmbs.get(j).getProjectName();
                   }else if(k==1){
                           celCount=pmbs.get(j).getSuoshudanwei();
                   }else if(k==2){
                       celCount=pmbs.get(j).getChiefAuditNames();
                   }else if(k==3){
                       celCount=pmbs.get(j).getCreateYear();
                   }else if(k==4){
                       celCount=pmbs.get(j).getCreUserId();
                   }else if(k==5){
                       celCount=pmbs.get(j).getShenhejieguo();
                   }else if(k==6){
                       celCount=pmbs.get(j).getBeizhu();
                   }
                   Phrase count = new Phrase(celCount, chinese2);//支持中文
                 //  count.setAlignment(Element.ALIGN_CENTER);
                   cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                   cell.addElement(count);
                   table.addCell(count);
               }
        
    }
           
           
      document.add(table);
      
      SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");
      Paragraph date = new Paragraph(sdf.format(new Date()),chinese2);   
      date.setAlignment(Element.ALIGN_RIGHT);   
      document.add(date);
      
      document.close();
      System.gc();
      return "success";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

IText 生成pdf,处理table cell列跨页缺失的问题的更多相关文章

  1. Java Itext 生成PDF文件

    利用Java Itext生成PDF文件并导出,实现效果如下: PDFUtil.java package com.jeeplus.modules.order.util; import java.io.O ...

  2. iText生成PDF 格式报表

    1.导包 <dependency> <groupId>com.lowagie</groupId> <artifactId>itext</artif ...

  3. 在linux环境下使用itext生成pdf

    转载请注明出处 https://www.cnblogs.com/majianming/p/9537173.html 项目中需要对订单生成pdf文件,在不断的尝试之后,终于生成了比较满意的pdf文档. ...

  4. 用itext生成PDF报错:Font 'STSong-Light1' with 'UniGB-UCS2-H' is not recognized.

    用itext生成PDF报错,加上try catch捕获到异常是 BaseFont bFont = BaseFont.createFont("STSong-Light1", &quo ...

  5. 【PDF】java使用Itext生成pdf文档--详解

    [API接口]  一.Itext简介 API地址:javadoc/index.html:如 D:/MyJAR/原JAR包/PDF/itext-5.5.3/itextpdf-5.5.3-javadoc/ ...

  6. java使用iText生成pdf表格

    转载地址:http://www.open-open.com/code/view/1424011530749 首先需要你自己下载itext相关的jar包并添加引用,或者在maven中添加如下引用配置: ...

  7. 【Java】使用iText生成PDF文件

    iText介绍 iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库.通过iText不仅可以生成PDF或rtf的文档,而且可以将XML.Html文件转 ...

  8. 使用 Itext 生成PDF

    一.生成PDF,所需jar包(itext-2.0.8.jar,iTextAsian.jar) 在springboot中只需要引入依赖即可,依赖代码如下: <dependency> < ...

  9. Itext生成pdf文件

    来源:https://my.oschina.net/lujianing/blog/894365 1.背景 在某些业务场景中,需要提供相关的电子凭证,比如网银/支付宝中转账的电子回单,签约的电子合同等. ...

随机推荐

  1. layer设置弹出全屏

    //弹出即全屏 var index = layer.open({ type: , content: 'http://www.layui.com', area: ['300px', '195px'], ...

  2. oracle的Hint

    与优化器模式相关的Hint 1 ALl_ROWS   让优化器启用CBO /*+ all_rows */ 2  first_rows(n)     让优化器启用CBO 模式,而且得到目标sql的执行计 ...

  3. 最小生成树 || HDU 1301 Jungle Roads

    裸的最小生成树 输入很蓝瘦 **并查集 int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } 找到x在并查集里的根结点,如果 ...

  4. Linux-03 Linux下的tar命令

    功能说明 用来建立,还原备份文件的工具程序,它可以加入,解开备份文件内的文件 参数 -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五 ...

  5. NOIP考纲

    首先来一张图,很直观(截止到2012年数据) 下面是收集的一些,我改了一下 红色加粗表示特别重要,必须掌握绿色加粗表示最好掌握,可能性不是很大,但是某些可以提高程序效率 高精度 a.加法 b.减法 c ...

  6. Redis那些事(一) — Redis简介

    本人最近在学习Redis的使用和底层原理,有一些收获,所以希望通过写博客的形式来记录自己的学习过程,加深自己的理解,同时也方便以后查阅复习.目前打算先记录一些基本的使用方法和部分底层实现,其他的如果有 ...

  7. 操作系统复习——如何查看一个进程的详细信息,如何追踪一个进程的执行过程 ,如何在 Linux 系统下查看 CPU、内存、磁盘、IO、网卡情况?epoll和select区别?

    1. 如何查看一个进程的详细信息,如何追踪一个进程的执行过程 通过pstree命令(根据pid)进行查询进程内部当前运行了多少线程:# pstree -p 19135(进程号) 使用top命令查看(可 ...

  8. sql语句执行顺序与性能优化(1)

    一.首先我们看一下mysql的sql语句的书写顺序 . select--distinct--from--on--where--group by--having--聚合函数cube.rollup--or ...

  9. l5-repository基本使用--结合使用artisan

    一.从头开始创建 1.执行以下artisan: php artisan make:entity Student 如果某个文件已经存在,则不会创建新的文件去覆盖原有的文件,案例如下: 2.修改model ...

  10. PLSQL Developer连接数据库报错ora-12514解决

    连接本地数据库报以上错误,需要修改本地数据库的监听配置文件(如下所示:) 比如我的本地oracle数据库相关文件在E:\app\user\product\11.2.0\dbhome_1下 然后在E:\ ...