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

青旅半醒 2022-12-30 13:42 405阅读 0赞

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

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

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

如果直接根据ftl模版中的

填充数据,如果表格列大于第一列填充空白,整个表格会整体移到第二页。

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

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

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  5. <meta http-equiv="Content-Style-Type" content="text/css"/>
  6. <title></title>
  7. <style type="text/css">
  8. body {
  9. font-family: pingfang sc light;
  10. }
  11. th,td{
  12. border: 1px #ccc;
  13. text-align: center;
  14. word-wrap : break-word ;
  15. word-break:break-all;
  16. }
  17. table{
  18. border-collapse: collapse;
  19. table-layout: fixed;
  20. }
  21. .firstLine{
  22. font-size:12px;
  23. height:25px;
  24. }
  25. .SecondLine{
  26. font-size:12px;
  27. height:25px;
  28. }
  29. .SecondLineOne{
  30. float: left;
  31. text-align: left;
  32. width: 40px;
  33. }
  34. .SecondLineTwo{
  35. float: left;
  36. text-align: left;
  37. width: 320px;
  38. }
  39. .SecondLineThree{
  40. width: 17px;
  41. float: left;
  42. }
  43. .SecondLineFour{
  44. float: left;
  45. text-align: left;
  46. width: 320px;
  47. }
  48. .vertical{
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <!--第一页开始-->
  54. <div class="center" style="width:697px;">
  55. <div>
  56. <div class="firstLine" >
  57. <div style="float: left;text-align: left;width: 40px;height: 25px;"></div>
  58. <span style="width: 60px;float: left;">流程编号:</span><span style="width: 597px;">${(info.processNumber)!}</span>
  59. </div>
  60. <div class="firstLine">
  61. <div style="float: left;text-align: left;width: 40px;height: 25px;"></div>
  62. <span style="width: 60px;float: left;">流程标题:</span><span style="width: 597px;">${(info.title)!}</span>
  63. </div>
  64. <div>
  65. <div class="SecondLine">
  66. <div class="SecondLineOne" ></div>
  67. <div class="SecondLineTwo" >所属公司:<span>${(info.company)!}</span></div>
  68. <div class="SecondLineThree" ></div>
  69. <div class="SecondLineFour">所在部门:<span>${(info.depart)!}</span></div>
  70. </div>
  71. </div>
  72. <div>
  73. <div class="SecondLine">
  74. <div class="SecondLineOne"></div>
  75. <div class="SecondLineTwo">申请人:<span>${(info.applicant)!}</span></div>
  76. <div class="SecondLineThree"></div>
  77. <div class="SecondLineFour">申请时间:<span>${(info.applicantDate)!}</span></div>
  78. </div>
  79. </div>
  80. <div class="firstLine">
  81. <div style="float: left;text-align: left;width: 40px;height: 25px;"></div>
  82. <span style="width: 60px;float: left;">联系方式:</span><span style="width: 597px;">${(info.contact)!}</span>
  83. </div>
  84. <div>
  85. <div class="SecondLine">
  86. <div class="SecondLineOne"></div>
  87. <div class="SecondLineTwo">紧急情况:<span>${(info.emergency)!}</span></div>
  88. <div class="SecondLineThree"></div>
  89. <div class="SecondLineFour">发票总张数:<span>${(info.invoiceNum)!}</span></div>
  90. </div>
  91. </div>
  92. <div>
  93. <div class="SecondLine" style="height: 35px;">
  94. <div class="SecondLineOne"></div>
  95. <div class="SecondLineTwo">费用所属部门:<span>${(info.costDepart)!}</span></div>
  96. <div class="SecondLineThree"></div>
  97. <div class="SecondLineFour">费用所属公司:<span style="width: 240px; word-wrap : break-word ;word-break:break-all;">${(info.costCompany)!}</span></div>
  98. </div>
  99. </div>
  100. <div>
  101. <div class="SecondLine">
  102. <div class="SecondLineOne"></div>
  103. <div class="SecondLineTwo">费用付款总金额:<span>${(info.amount)!}</span></div>
  104. <div class="SecondLineThree"></div>
  105. <div class="SecondLineFour">费用付款总金额大写:<span>${(info.amountCapital)!}</span></div>
  106. </div>
  107. </div>
  108. <div class="firstLine">
  109. <div style="float: left;text-align: left;width: 40px;height: 25px;"></div>
  110. <span style="width: 60px;float: left;">是否后补发票:</span><span style="width: 597px;">${(info.supply)!}</span>
  111. </div>
  112. <#if (info.remarks)?? >
  113. <div class="firstLine" style="height: 50px;">
  114. <div style="float: left;text-align: left;width: 40px;height: 25px;"></div>
  115. <span style="width: 60px;float: left;">备注:</span><span style="width: 597px; word-wrap : break-word ;word-break:break-all;">${(info.remarks)!}</span>
  116. </div >
  117. </#if>
  118. </div>
  119. <div class="page">
  120. <div style="float: left;width: 617px;position: relative;right: -40px;">
  121. <table class="moduleTable">
  122. <thead>
  123. <tr>
  124. <th style="width: 40px;height:20px;"><span style="font-size:10px;">费用科目</span></th>
  125. <th style="width: 80px;height:20px;"><span style="font-size:10px;">付款金额</span></th>
  126. <th style="width: 80px;height:20px;"><span style="font-size:10px;">确认金额</span></th>
  127. <th style="width: 20px;height:20px;"><span style="font-size:10px;">发票张数</span></th>
  128. <th style="width: 121px;height:20px;"><span style="font-size:10px;">收款人账户名称及帐号</span></th>
  129. <th style="width: 110px;height:20px;"><span style="font-size:10px;">收款人开户银行及支行</span></th>
  130. <th style="width: 20px;height:20px;"><span style="font-size:10px;">账户类型</span></th>
  131. <th style="width: 160px;height:20px;"><span style="font-size:10px;">事由</span></th>
  132. </tr>
  133. </thead>
  134. </table>
  135. </div>
  136. <#list module as module>
  137. <div style="float: left;width: 617px;position: relative;right: -40px;">
  138. <table class="moduleTable">
  139. <tbody>
  140. <tr>
  141. <td style="text-align: center;width: 40px;valign:top;height:50px;"><span style="font-size:10px;">${(module.subject)!}</span></td>
  142. <td style="text-align: center;width: 80px;height:50px;"><span style="font-size:10px;">${(module.amount)!}</span></td>
  143. <td style="text-align: center;width: 80px;height:50px;"><span style="font-size:10px;">${(module.confirm)!}</span></td>
  144. <td style="text-align: center;width: 20px;height:50px;"><span style="font-size:10px;">${(module.attachno)!}</span></td>
  145. <td style="text-align: center;width: 121px;height:50px;"><span style="font-size:10px;">${(module.accountTitle)!}<br/>${(module.account)!}</span></td>
  146. <td style="text-align: center;width: 110px;height:50px;"><span style="font-size:10px;">${(module.accountBank)!}<br/>${(module.openBank)!}</span></td>
  147. <td style="text-align: center;width: 20px;height:50px;"><span style="font-size:10px;">${(module.type)!}</span></td>
  148. <td style="text-align: center;width: 160px;height:50px;"><span style="font-size:10px;">${(module.reason)!}</span></td>
  149. </tr>
  150. </tbody>
  151. </table>
  152. </div>
  153. </#list>
  154. </div>
  155. <div class="firstLine"></div>
  156. <div class="page">
  157. <div style="float: left;text-align: left;width: 40px;"></div>
  158. <div style="float: left;width: 617px;position: relative;">
  159. <table>
  160. <thead>
  161. <tr>
  162. <th style="width: 91px;height:15px;"><span style="font-size:10px;">执行环节</span></th>
  163. <th style="width: 92px;height:15px;"><span style="font-size:10px;">执行人</span></th>
  164. <th style="width: 92px;height:15px;"><span style="font-size:10px;">开始时间</span></th>
  165. <th style="width: 91px;height:15px;"><span style="font-size:10px;">结束时间</span></th>
  166. <th style="width: 90px;height:15px;"><span style="font-size:10px;">提交意见</span></th>
  167. <th style="width: 90px;height:15px;"><span style="font-size:10px;">审批方式</span></th>
  168. <th style="width: 90px;height:15px;"><span style="font-size:10px;">任务历时</span></th>
  169. </tr>
  170. </thead>
  171. </table>
  172. </div>
  173. <#list record as record>
  174. <div style="float: left;width: 617px;position: relative;right: -40px;"">
  175. <table>
  176. <tbody>
  177. <tr>
  178. <td style="width: 91px;height:15px;"><span style="font-size:10px;height:30px;">${(record.link)!}</span></td>
  179. <td style="width: 92px;height:15px;"><span style="font-size:10px;height:30px;">${(record.user)!}</span></td>
  180. <td style="width: 92px;height:15px;"><span style="font-size:10px;height:30px;">${(record.createTime)!}</span></td>
  181. <td style="width: 91px;height:15px;"><span style="font-size:10px;height:30px;">${(record.endDate)!}</span></td>
  182. <td style="width: 90px;height:15px;"><span style="font-size:10px;height:30px;">${(record.opinion)!}</span></td>
  183. <td style="width: 90px;height:15px;"><span style="font-size:10px;height:30px;">${(record.way)!}</span></td>
  184. <td style="width: 90px;height:15px;"><span style="font-size:10px;height:30px;">${(record.duration)!}</span></td>
  185. </tr>
  186. </tbody>
  187. </table>
  188. </div>
  189. </#list>
  190. </div>
  191. </div>
  192. </body>
  193. </html>

发表评论

表情:
评论列表 (有 0 条评论,405人围观)

还没有评论,来说两句吧...

相关阅读

    相关 itext生成pdf

    最近做一个结算项目,客户提出需要将结算出来的结果,批量的发给相应供应商进行价钱确认,确认完成后,再进行开票操作,最重要的是要把公司的公章用上。 就考虑了生成pdf的方式来实

    相关 itext 生成pdf

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

    相关 itext 生成pdf

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

    相关 iText生成PDF

    一、什么是PDF         PDF全称Portable Document Format,是Adobe公司开发的电子文件格式。这种文件格式与操作系统平台无关,也就是说,P