如何在Apache FOP的<fo:table/>中添加空行填充region-body区域
实现方案
1. 填充第1页body-region末尾空白
在table 1和table 2之间插入无内容的弹性填充块,会自动占满当前页剩余可用空间,当页面剩余空间不足以放下table 2时,刚好可以把第一页的空白区域填满:
<!-- 插入在table 1结束标签之后,table 2开始标签之前 --> <fo:leader leader-length.minimum="0pt" leader-length.optimum="100%" leader-length.maximum="100%" rule-thickness="0pt"/>
rule-thickness="0pt"表示无可见线条,仅作为空白填充- 100%长度配置会自动适配当前body-region的剩余可用高度
2. 第2页到最后一页固定插入13行空行
利用XSL-FO的page-position属性做条件渲染,仅非第一页的位置会渲染这段空行内容:
<!-- 插入在上述弹性填充块之后,table 2开始标签之前 --> <fo:block page-position="rest"> <!-- 13行空行,可根据需求调整line-height参数控制行高 --> <fo:block line-height="12pt"/><fo:block line-height="12pt"/><fo:block line-height="12pt"/> <fo:block line-height="12pt"/><fo:block line-height="12pt"/><fo:block line-height="12pt"/> <fo:block line-height="12pt"/><fo:block line-height="12pt"/><fo:block line-height="12pt"/> <fo:block line-height="12pt"/><fo:block line-height="12pt"/><fo:block line-height="12pt"/> <fo:block line-height="12pt"/> </fo:block>
page-position="rest"表示这段块仅在文档第一页之外的所有页面渲染,刚好匹配第2页到最后一页的要求- 也可直接给外层块设置
height属性控制总空白高度,比如行高12pt的13行空白可以直接写height="156pt"
完整层级结构参考
<fo:table><!-- table 1 全部代码 --></fo:table> <!-- 第一页空白填充块 --> <fo:leader leader-length.minimum="0pt" leader-length.optimum="100%" leader-length.maximum="100%" rule-thickness="0pt"/> <!-- 非第一页才显示的13行空行 --> <fo:block page-position="rest" height="156pt"/> <fo:table keep-together.within-page="always"><!-- table 2 全部代码 --></fo:table>
内容的提问来源于stack exchange,提问作者kieuanhvu
相关产品推荐
相关产品推荐

