itext根据freemarks模版生成pdf,表格跨页问题解决

使用itext根据freemarks模版生成pdf,表格产生跨页问题解决方法

java根据模版动态生成pdf的文章点击打开链接

  使用XMLWorkerHelper.getInstance().parseXHtml();生成pdf。

如果直接根据ftl模版中的<table></table>填充数据,如果表格列大于第一列填充空白,整个表格会整体移到第二页。

整个表格列大于整页pdf空白,会直接不显示表格。主要看我<#list></list>循环的模版代码,就可以完全解决这个问题。

我的list中循环的是div+表格

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

<meta http-equiv="Content-Style-Type" content="text/css"/>

<title></title>

<style type="text/css">

body {

font-family: pingfang sc light;

}




th,td{

border: 1px #ccc;

text-align: center;

word-wrap : break-word ;

word-break:break-all;

}

table{

border-collapse: collapse;

table-layout: fixed;

}

.firstLine{

font-size:12px;

height:25px;

}

.SecondLine{

font-size:12px;

height:25px;

}

.SecondLineOne{

float: left;

text-align: left;

width: 40px;

}

.SecondLineTwo{

float: left;

text-align: left;

width: 320px;

}

.SecondLineThree{

width: 17px;

float: left;


}

.SecondLineFour{

float: left;

text-align: left;

width: 320px;

}

.vertical{

}

</style>

</head>

<body>

<!--第一页开始-->


<div class="center" style="width:697px;">

<div>

<div class="firstLine" >

<div style="float: left;text-align: left;width: 40px;height: 25px;"></div>

<span style="width: 60px;float: left;">流程编号:</span><span style="width: 597px;">${(info.processNumber)!}</span>

</div>

<div class="firstLine">

<div style="float: left;text-align: left;width: 40px;height: 25px;"></div>

<span style="width: 60px;float: left;">流程标题:</span><span style="width: 597px;">${(info.title)!}</span>

</div>

<div>

<div class="SecondLine">

<div class="SecondLineOne" ></div>

<div class="SecondLineTwo" >所属公司:<span>${(info.company)!}</span></div>

<div class="SecondLineThree" ></div>

<div class="SecondLineFour">所在部门:<span>${(info.depart)!}</span></div>

</div>

</div>

<div>

<div class="SecondLine">

<div class="SecondLineOne"></div>

<div class="SecondLineTwo">申请人:<span>${(info.applicant)!}</span></div>

<div class="SecondLineThree"></div>

<div class="SecondLineFour">申请时间:<span>${(info.applicantDate)!}</span></div>

</div>

</div>

<div class="firstLine">

<div style="float: left;text-align: left;width: 40px;height: 25px;"></div>

<span style="width: 60px;float: left;">联系方式:</span><span style="width: 597px;">${(info.contact)!}</span>

</div>

<div>

<div class="SecondLine">

<div class="SecondLineOne"></div>

<div class="SecondLineTwo">紧急情况:<span>${(info.emergency)!}</span></div>

<div class="SecondLineThree"></div>

<div class="SecondLineFour">发票总张数:<span>${(info.invoiceNum)!}</span></div>

</div>

</div>

<div>

<div class="SecondLine" style="height: 35px;">

<div class="SecondLineOne"></div>

<div class="SecondLineTwo">费用所属部门:<span>${(info.costDepart)!}</span></div>

<div class="SecondLineThree"></div>

<div class="SecondLineFour">费用所属公司:<span style="width: 240px; word-wrap : break-word ;word-break:break-all;">${(info.costCompany)!}</span></div>

</div>

</div>

<div>

<div class="SecondLine">

<div class="SecondLineOne"></div>

<div class="SecondLineTwo">费用付款总金额:<span>${(info.amount)!}</span></div>

<div class="SecondLineThree"></div>

<div class="SecondLineFour">费用付款总金额大写:<span>${(info.amountCapital)!}</span></div>

</div>

</div>

<div class="firstLine">

<div style="float: left;text-align: left;width: 40px;height: 25px;"></div>

<span style="width: 60px;float: left;">是否后补发票:</span><span style="width: 597px;">${(info.supply)!}</span>

</div>

<#if (info.remarks)?? >

<div class="firstLine" style="height: 50px;">

<div style="float: left;text-align: left;width: 40px;height: 25px;"></div>

<span style="width: 60px;float: left;">备注:</span><span style="width: 597px; word-wrap : break-word ;word-break:break-all;">${(info.remarks)!}</span>

</div >

</#if>

</div>

<div class="page">

<div style="float: left;width: 617px;position: relative;right: -40px;">

<table class="moduleTable">

<thead>

<tr>

<th style="width: 40px;height:20px;"><span style="font-size:10px;">费用科目</span></th>

<th style="width: 80px;height:20px;"><span style="font-size:10px;">付款金额</span></th>

<th style="width: 80px;height:20px;"><span style="font-size:10px;">确认金额</span></th>

<th style="width: 20px;height:20px;"><span style="font-size:10px;">发票张数</span></th>

<th style="width: 121px;height:20px;"><span style="font-size:10px;">收款人账户名称及帐号</span></th>

<th style="width: 110px;height:20px;"><span style="font-size:10px;">收款人开户银行及支行</span></th>

<th style="width: 20px;height:20px;"><span style="font-size:10px;">账户类型</span></th>

<th style="width: 160px;height:20px;"><span style="font-size:10px;">事由</span></th>

</tr>

</thead>

</table>

</div>

<#list module as module>

<div style="float: left;width: 617px;position: relative;right: -40px;">

<table class="moduleTable">

<tbody>

<tr>

<td style="text-align: center;width: 40px;valign:top;height:50px;"><span style="font-size:10px;">${(module.subject)!}</span></td>

<td style="text-align: center;width: 80px;height:50px;"><span style="font-size:10px;">${(module.amount)!}</span></td>

<td style="text-align: center;width: 80px;height:50px;"><span style="font-size:10px;">${(module.confirm)!}</span></td>

<td style="text-align: center;width: 20px;height:50px;"><span style="font-size:10px;">${(module.attachno)!}</span></td>

<td style="text-align: center;width: 121px;height:50px;"><span style="font-size:10px;">${(module.accountTitle)!}<br/>${(module.account)!}</span></td>

<td style="text-align: center;width: 110px;height:50px;"><span style="font-size:10px;">${(module.accountBank)!}<br/>${(module.openBank)!}</span></td>

<td style="text-align: center;width: 20px;height:50px;"><span style="font-size:10px;">${(module.type)!}</span></td>

<td style="text-align: center;width: 160px;height:50px;"><span style="font-size:10px;">${(module.reason)!}</span></td>

</tr>

</tbody>

</table>

</div>

</#list>

</div>

<div class="firstLine"></div>

<div class="page">

<div style="float: left;text-align: left;width: 40px;"></div>

<div style="float: left;width: 617px;position: relative;">

<table>

<thead>

<tr>

<th style="width: 91px;height:15px;"><span style="font-size:10px;">执行环节</span></th>

<th style="width: 92px;height:15px;"><span style="font-size:10px;">执行人</span></th>

<th style="width: 92px;height:15px;"><span style="font-size:10px;">开始时间</span></th>

<th style="width: 91px;height:15px;"><span style="font-size:10px;">结束时间</span></th>

<th style="width: 90px;height:15px;"><span style="font-size:10px;">提交意见</span></th>

<th style="width: 90px;height:15px;"><span style="font-size:10px;">审批方式</span></th>

<th style="width: 90px;height:15px;"><span style="font-size:10px;">任务历时</span></th>

</tr>

</thead>

</table>

</div>

<#list record as record>

<div style="float: left;width: 617px;position: relative;right: -40px;"">

<table>

<tbody>

<tr>

<td style="width: 91px;height:15px;"><span style="font-size:10px;height:30px;">${(record.link)!}</span></td>

<td style="width: 92px;height:15px;"><span style="font-size:10px;height:30px;">${(record.user)!}</span></td>

<td style="width: 92px;height:15px;"><span style="font-size:10px;height:30px;">${(record.createTime)!}</span></td>

<td style="width: 91px;height:15px;"><span style="font-size:10px;height:30px;">${(record.endDate)!}</span></td>

<td style="width: 90px;height:15px;"><span style="font-size:10px;height:30px;">${(record.opinion)!}</span></td>

<td style="width: 90px;height:15px;"><span style="font-size:10px;height:30px;">${(record.way)!}</span></td>

<td style="width: 90px;height:15px;"><span style="font-size:10px;height:30px;">${(record.duration)!}</span></td>

</tr>

</tbody>

</table>

</div>

</#list>

</div>

</div>


</body>

</html>

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值