Java 如何避免单元格内容在页面之间拆分?

Java 如何避免单元格内容在页面之间拆分?,java,pdf,xslt,xsl-fo,apache-fop,Java,Pdf,Xslt,Xsl Fo,Apache Fop,我有一个XSL-FO文件,然后使用fop0.20.5将其转换为PDF文件。我有一个表格,每个页面、页眉和页脚上都会显示页眉列 我对输出的问题如下:属于第5列中某个单元格的文本在页面之间分割(在下一页中,只有部分文本不适合上一页,行中的其他单元格为空)。 如何防止这种行为?我希望将整个内容放在下一页上,而不仅仅是文本的一部分(因此,当这种情况发生时,上一页上不应存在最后一行,而是将整行移到下一页) xsl文件中的部分代码: <?xml version="1.0"

我有一个XSL-FO文件,然后使用fop0.20.5将其转换为PDF文件。我有一个表格,每个页面、页眉和页脚上都会显示页眉列

我对输出的问题如下:属于第5列中某个单元格的文本在页面之间分割(在下一页中,只有部分文本不适合上一页,行中的其他单元格为空)。
如何防止这种行为?我希望将整个内容放在下一页上,而不仅仅是文本的一部分(因此,当这种情况发生时,上一页上不应存在最后一行,而是将整行移到下一页)

xsl文件中的部分代码:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet exclude-result-prefixes="fo" 
version="1.1" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:java="java" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output method="xml" 
version="1.0" 
omit-xml-declaration="no" 
indent="yes"/>

布局主集部件:

 <fo:layout-master-set>
                <fo:simple-page-master master-name="A4" page-height="29.7cm" page-width="21.0cm" margin-top="0.5cm" margin-bottom="0.5cm" margin-left="2.0cm" margin-right="2.0cm">
                        <fo:region-before region-name="xsl-region-before" extent="2cm"/>
                        <fo:region-body region-name="xsl-region-body" margin-top="2cm" margin-bottom="4.0cm"/>
                        <fo:region-after region-name="xsl-region-after" extent="2.5cm"/>
                    </fo:simple-page-master>
    </fo:layout-master-set>

表部分:

<fo:flow flow-name="xsl-region-body">

             <fo:table table-layout="fixed">

                        <fo:table-column column-width="{$PAR_C1SIZE}cm"/>
                         ...
                         <!-- more table-column def. -->
                         ...
                         ... 
                        <xsl:if test="string-length($PAR_MODIFY) &gt; 0">
                            <fo:table-column column-width="0.3cm"/>
                        </xsl:if>
                        <fo:table-header>
                            <fo:table-row>
                                <xsl:attribute name="background-color">#60c3d9</xsl:attribute>
                                <fo:table-cell display-align="center" border-top="0.05em solid #60c3d9" border-right="0.05em solid white">
                                    
                                    <fo:block text-align="center" color="white" font-weight="bold">Date blabla</fo:block>
                                
                                </fo:table-cell>
                                ...
                                ...
                                <!-- more cells -->
                                ...
                                ...
                                ...
                            </fo:table-row>
                        </fo:table-header>
                        <fo:table-body>
                            <xsl:apply-templates select="POS"/>
                        </fo:table-body>
                    </fo:table>
</fo:flow>

...
...
... 
#60c3d9
日期布拉布拉
...
...
...
...
...
行部分:

<xsl:template match="POS">
        <xsl:apply-templates select="SP"></xsl:apply-templates>
</xsl:template>


<xsl:template match="SP">
        <fo:table-row >

            <fo:table-cell display-align="center" border="0.05em solid grey" >
                <fo:block text-align="center">
                    <xsl:value-of select="'Bla bla bla'"/>
                </fo:block>

            </fo:table-cell>
            

            <fo:table-cell display-align="center" border="0.05em solid grey">
                <fo:block text-align="center">
                        <xsl:value-of select="'Bla bla bla 2222..'"/>
                </fo:block>
            </fo:table-cell>
            
            ...
            ...
            ...
            <!-- more table-cells -->
            ...
            ...
            ...
            ...
        </fo:table-row>
</xsl:template>

...
...
...
...
...
...
...

是什么导致了这种行为?我如何修复它?

正如@MartinHonnen所说,FOP0.20.5非常古老。您可以在
fo:table行
fo:table单元格
中的一个或两个上尝试保持在一起。我对早期的FOP版本有一个模糊的记忆,在FOP支持很多关于keeps的其他功能之前,它就已经实现了


您也可以尝试为
孤儿
和/或
寡妇
设置一个较大的值,以查看这是否会阻止您的段落中断。

在CSS
tr{page break inside:avoid}
中,我认为对于XSL-FO,可以为表/表行设置类似的属性或属性。测试是否将
等应用于表行元素可以解决问题:Sry我使用fop-0.20.5.jar将XSL转换为pdf。不幸的是,将其添加到表行并没有起到任何作用@MartinHonnen.O。有些东西似乎太旧了,我认为2.5是当前版本