Itext genera pdf basado en la plantilla de freemarks y resuelve el problema de la difusión de formularios

Utilice itext para generar pdf basado en la plantilla de marcas gratuitas y la solución al problema entre páginas causado por el formulario

Java genera dinámicamente un artículo en pdf de acuerdo con la plantilla haga clic para abrir el enlace

  Utilice XMLWorkerHelper.getInstance (). ParseXHtml (); para generar pdf.

Si los datos se llenan directamente de acuerdo con la <tabla> </table> en la plantilla ftl, si la columna de la tabla es más grande que la primera columna y el espacio en blanco está lleno, toda la tabla se moverá a la segunda página como un todo .

Si toda la columna de la tabla es más grande que la página completa del pdf, la tabla no se mostrará directamente. Principalmente, vea mi código de plantilla de bucle <#list> </list>, puede resolver completamente este problema.

El bucle en mi lista es div + table

<!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>

 

 

 

Supongo que te gusta

Origin blog.csdn.net/yucaifu1989/article/details/111698263
Recomendado
Clasificación