IText 生成pdf,处理table cell列跨页缺失的问题

/**
     * 创建(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);
      // 标题居中处理:文章来源地址https://www.yii666.com/article/756271.html网址:yii666.com

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";
        }
    }文章地址https://www.yii666.com/article/756271.html网址:yii666.com<文章来源地址:https://www.yii666.com/article/756271.html

版权声明:本文内容来源于网络,版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。文本页已经标记具体来源原文地址,请点击原文查看来源网址,站内文章以及资源内容站长不承诺其正确性,如侵犯了您的权益,请联系站长如有侵权请联系站长,将立刻删除

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

  1. ID基本操作(复制页面)(移动页面)(调整跨页页数)(版面调整)5.16

  2. AT24C02跨页写数据

  3. 关于云主机Thinkphp框架Session跨页失效的问题

  4. IText 生成pdf,处理table cell列跨页缺失的问题

  5. laydate年份选择,关闭底框,点击指定年份就选择然后关闭控件,翻页不选择也不关闭控件

  6. Java 设置PDF跨页表格重复显示表头行

    在创建表格时,如果表格内容出现跨页显示的时候,默认情况下该表格的表头不会在下一页显示,在阅读体验上不是很好。下面分享一个方法如何在表格跨页是显示表格的表头内容,这里只需要简单使用方法 grid.setRepeatHeader(true);  即可。具体参考如下方法步骤。1.导入Jar包这

  7. easyui datagrid 跨页选择

    $.fn.extend( memberList ,{quickSearch : function() {var time1 = new Date();/* this.datagrid.datagrid(\\\'clearSelections\\\');  */if(this.advSearchForm) {this.searchForm.setBaseConditions(this.advSearchForm.getConditions());}if( this.beforeSearch(this.searchForm.getQo()) ){/* this.datagrid.datagrid(\\\'clearSelections\\\');  */this.datagrid.datagrid(\\\'load\\\', {searchCond

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信图片_20190322181744_03.jpg

微信扫一扫打赏

请作者喝杯咖啡吧~

支付宝扫一扫领取红包,优惠每天领

二维码1

zhifubaohongbao.png

二维码2

zhifubaohongbao2.png