简体   繁体   English

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

[英]How can I avoid having the content of a cell split between pages?

I have an XSL-FO file that is then transformed into a PDF file using FOP 0.20.5.我有一个XSL-FO文件,然后使用 FOP 0.20.5 将其转换为 PDF 文件。 I have a table with header columns that are shown on every page, header and footer.我有一个表格,其中包含 header 列,每页都显示,header 和页脚。

My problem with the output is the following: the text that belongs to a cell in the 5th column is split between pages (in the next page there is only the part of text that didn't somehow fit on previous page, other cells in the row are empty).我对 output 的问题如下:属于第 5 列中的单元格的文本在页面之间拆分(在下一页中,只有部分文本不适合上一页,其他单元格在行为空)。
How can i prevent this behaviour?我怎样才能防止这种行为? Instead of that move I would like the whole content to be placed on the next page, not just a part of that text (so of course when this happens last row shouldn't exist on previous page but the whole row is moved to next page).我希望将整个内容放在下一页而不是该移动,而不仅仅是该文本的一部分(所以当然,当这种情况发生时,最后一行不应该存在于上一页,而是整行移到下一页)。

电流输出

Parts of code from xsl file: 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"/>

Layout-master-set part: Layout-master-set 部分:

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

Table part:表格部分:

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

Row part:行部分:

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

What is causing this behaviour and how can i fix it?是什么导致了这种行为,我该如何解决?

As @MartinHonnen said, FOP 0.20.5 is very old.正如@MartinHonnen 所说,FOP 0.20.5 已经很老了。 You could try keep-together.within-page="always" (see https://www.w3.org/TR/xsl11/#keep-together ) on either or both of the fo:table-row and fo:table-cell .您可以在fo:table-rowfo:table-cell中的一个或两个上尝试keep-together.within-page="always" (参见https://www.w3.org/TR/xsl11/#keep-togetherfo:table-cell I have a vague memory of early FOP versions implementing that before FOP supported much else about keeps.我有一个模糊的 memory 早期 FOP 版本,在 FOP 支持很多其他关于保留之前实现它。

You could also try setting a large value for orphans and/or widows to see if that will stop your paragraph from breaking.您也可以尝试为orphans和/或widows设置一个较大的值,看看这是否会阻止您的段落中断。

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

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