简体   繁体   English

如何避免在 Apache fop 中的页尾拆分表

[英]How to avoid splitting of table at page end in Apache fop

I am trying to create a PDF using Apache FOP.我正在尝试使用 Apache FOP 创建 PDF。 I have a section of input which repeats as many number of times.我有一段输入重复多次。 With each section i have a table created in the page.对于每个部分,我在页面中创建了一个表格。 After about 3 tables, there is a page break and the table is split into the current and the next page.在大约 3 个表格之后,有一个分页符,表格被分成当前页和下一页。 I would want to avoid this and have the entire table in the next page.我想避免这种情况,并将整个表格放在下一页中。 Could you please guide as i am very new to Apache FOP.您能否指导一下,因为我对 Apache FOP 很陌生。

XML section that contributes for table: XML 部分有助于表:

<SummaryDetails> 
<SummaryDetail>
<MediaType>P</MediaType>
<T1>
<T1ID>I</T1ID>
<T2>
<T2ID>T2</T2ID>
 <T3>
 <T3ID>T3</T3ID>
 </T3>
 </T2>
 /T1>
 </SummaryDetail>
 </SummaryDetails>

Code snippet:代码片段:

The table consists of nested loop for T1, T2 and T3 sections in the xml.该表由 xml 中 T1、T2 和 T3 部分的嵌套循环组成。 The table appears ok until it encounters a page break.在遇到分页符之前,该表显示正常。

<fo:page-sequence master-reference="A4-first" force-page-count="no-force" id="end">

<!--Header of table which appears in all pages-->
<fo:static-content flow-name="xsl-region-before">
<fo:table >
<fo:table-column column-width="5.8cm"/>
<fo:table-column column-width="8.1cm"/>
<fo:table-column column-width="4.8cm"/>
<fo:table-body>
<fo:table-row height="3.1cm">
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>

<!--Body of table-->
<fo:flow flow-name="body">
<!--This table appears only when the number of SummaryDetails section is greater than 1 and 
appears just once-->
<xsl:choose>
<xsl:when test="count(./SummaryDetails) &gt; 1">
<fo:table margin-left="0.2cm"  >
<fo:table-body>
<fo:table-row>
</fo:table-row>
</fo:table-body>
</fo:table>
</xsl:when>
</xsl:choose>

<!--This is the table which is having the issue-->
<fo:table>
<fo:table-body>
<xsl:for-each select="SummaryDetails">
<fo:table-row >
</fo:table-row>

<xsl:for-each select="SummaryDetail/T1">
<fo:table-row >
</fo:table-row>
<xsl:for-each select="T2">
<fo:table-row >
</fo:table-row>
<xsl:for-each select="T3">       
<fo:table-row >
</fo:table-row>
</xsl:for-each>
<fo:table-row >
</fo:table-row>
</xsl:for-each>
<fo:table-row>
</fo:table-row>
</xsl:for-each>
<fo:table-row>
</fo:table-row>
<fo:table-row>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>

The input xml is also explained here: How to insert a new page when a table inside a for each block overflows from the current page sequence in Apache fop此处还解释了输入 xml: How to insert a new page when a table inside a for each block 从 Apache fop 中的当前页序列溢出时

Use <fo:table keep-together.within-page="always"> .使用<fo:table keep-together.within-page="always">

See https://www.w3.org/TR/xsl11/#keep-together .请参阅https://www.w3.org/TR/xsl11/#keep-together The FOP compliance page states that FOP has limited support for keep-together ( https://xmlgraphics.apache.org/fop/compliance.html#fo-property-keep-together ), but I would expect it to work on tables. FOP 合规性页面指出 FOP 对keep-together ( https://xmlgraphics.apache.org/fop/compliance.html#fo-property-keep-together ) 的支持有限,但我希望它适用于表格。

I tried using keep-with-next.within-page="always" in every row of the table and keep-with-next.within-page="always" on the 1st table cell and it worked out wonders.我尝试在表格的每一行中使用 keep-with-next.within-page="always" 并在第一个表格单元格中使用 keep-with-next.within-page="always" ,它创造了奇迹。 :) :)

<!--This is the table which is having the issue-->
<fo:table>
<fo:table-body>
<xsl:for-each select="SummaryDetails">
<fo:table-row keep-with-next.within-page="always">
<fo:table-cell keep-with-next.within-page="always"></fo:table-cell>
</fo:table-row>

<xsl:for-each select="SummaryDetail/T1">
<fo:table-row keep-with-next.within-page="always">
<fo:table-cell keep-with-next.within-page="always"></fo:table-cell>
</fo:table-row>
<xsl:for-each select="T2">
<fo:table-row keep-with-next.within-page="always">
</fo:table-row>
<xsl:for-each select="T3">       
<fo:table-row keep-with-next.within-page="always">
</fo:table-row>
</xsl:for-each>
<fo:table-row keep-with-next.within-page="always">
</fo:table-row>
</xsl:for-each>
<fo:table-row keep-with-next.within-page="always">
</fo:table-row>
</xsl:for-each>
<fo:table-row keep-with-next.within-page="always">
</fo:table-row>
<fo:table-row keep-with-next.within-page="always">
</fo:table-row >
</xsl:for-each>
</fo:table-body>
</fo:table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM