【问题标题】:XSL FO setting content to the bottom of the page failsXSL FO 将内容设置到页面底部失败
【发布时间】:2013-10-22 05:38:14
【问题描述】:

我正在尝试在页面底部打印表格(A4 格式),但不是那样,最后一个表格会在前一个元素之后继续打印,尽管有 margin-bottom 属性。另外,如果我尝试设置页脚(使用 fo:footnote 和 fo:inline) - 此页脚也不会出现在页面底部,而是出现在最后一个元素下。

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:template match="/">
        <fo:root>
            <fo:layout-master-set >
                <fo:simple-page-master master-name="simple" page-height="29.7cm" page-width="21cm"
                                       margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
                    <fo:region-body />
                    <!--<fo:region-after region-name="first-page-footer" margin-bottom="2cm" extent="11in" display-align="after"/>-->
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="simple">
                <xsl:call-template name="mainTemplate"/>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>

    <xsl:template name="mainTemplate">

        <xsl:variable name="newline">
            <xsl:text>&#160;</xsl:text>
        </xsl:variable>
        <xsl:variable name="logoURL" >
            <xsl:value-of select="/export/logotype"/>
        </xsl:variable>
        <xsl:variable name="signatureURL">
            <xsl:value-of select="/export/signature"/>
        </xsl:variable>

        <fo:flow flow-name="xsl-region-body">
            <fo:block space-before="2cm" space-after="2cm" font-size="12pt"
                      font-family="Times New Roman">

                <fo:block  space-before="2cm" space-after="2cm" >
                    <fo:table  border-color="black" border-style="solid"
                          border-width="0.5pt"  >
                        <fo:table-column column-width="3cm" border-color="black" border-style="solid"
                                     border-width="0.5pt"/>
                        <fo:table-column column-width="3cm" border-color="black" border-style="solid"
                                     border-width="0.5pt"/>
                        <fo:table-column column-width="3cm" border-color="black" border-style="solid"
                                     border-width="0.5pt"/>
                        <fo:table-column column-width="8cm" border-color="black" border-style="solid"
                                     border-width="0.5pt"/>
                        <fo:table-body>
                            <fo:table-row>
                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block font-weight="bold" text-align="center">Number</fo:block>
                                </fo:table-cell>
                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block font-weight="bold" text-align="center">Date</fo:block>
                                </fo:table-cell>
                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block font-weight="bold" text-align="center">Bill</fo:block>
                                </fo:table-cell>
                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block font-weight="bold" text-align="center">Owner</fo:block>
                                </fo:table-cell>
                            </fo:table-row>

                            <xsl:for-each select="/export/Cars/car">
                                <xsl:variable name="param1" select="number"/>
                                <xsl:variable name="param2" select="date"/>
                                <xsl:variable name="param3" select="bill"/>
                                <xsl:variable name="param4" select="owner"/>
                                <fo:table-row>
                                    <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt"
                                               padding-left="3pt">
                                        <fo:block text-align="center">
                                            <xsl:value-of select="$param1"/>
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt"
                                               padding-left="3pt" padding-right="3pt" display-align="center">
                                        <fo:block text-align="center">
                                            <xsl:value-of select="$param2"/>
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt"
                                               padding-left="3pt" padding-right="3pt" display-align="center">
                                        <fo:block text-align="center">
                                            <xsl:value-of select="$param3"/>
                                        </fo:block>
                                    </fo:table-cell >
                                    <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt"
                                               padding-left="3pt" padding-right="3pt" display-align="center">
                                        <fo:block text-align="center">
                                            <xsl:value-of select="$param4"/>
                                        </fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                            </xsl:for-each>
                        </fo:table-body>
                    </fo:table>
                </fo:block>

                <fo:block>
                    <xsl:value-of select="$newline"/>
                </fo:block>
                <fo:block>
                    <xsl:value-of select="$newline"/>
                </fo:block>

                <fo:block space-after="2cm" >
                    <fo:table  border-color="black" border-style="solid"
                               border-width="0.5pt"  >
                        <fo:table-column column-width="3cm" border-color="black" border-style="solid" border-width="0.5pt"/>
                        <fo:table-column column-width="14cm" border-color="black" border-style="solid" border-width="0.5pt"/>
                        <fo:table-body>
                            <fo:table-row>
                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block font-weight="bold" text-align="center">Graph 6</fo:block>
                                </fo:table-cell>

                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block  text-align="center"><xsl:value-of select="/export/graph6"/></fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block font-weight="bold" text-align="center">Graph 5</fo:block>
                                </fo:table-cell>

                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block  text-align="center"><xsl:value-of select="/export/graph5"/></fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block font-weight="bold" text-align="center">Graph 4</fo:block>
                                </fo:table-cell>

                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block  text-align="center"><xsl:value-of select="/export/graph4"/></fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block font-weight="bold" text-align="center">Graph1</fo:block>
                                </fo:table-cell>

                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block  text-align="center"><xsl:value-of select="/export/graph1"/></fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block font-weight="bold" text-align="center">Graph 2</fo:block>
                                </fo:table-cell>

                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block  text-align="center"><xsl:value-of select="/export/graph2"/></fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block font-weight="bold" text-align="center">Graph3</fo:block>
                                </fo:table-cell>

                                <fo:table-cell border-color="black" border-style="solid" border-width="0.5pt">
                                    <fo:block  text-align="center"><xsl:value-of select="/export/graph3"/></fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </fo:table-body>
                    </fo:table>
                </fo:block>

                <fo:block>
                    <xsl:value-of select="$newline"/>
                </fo:block>
                <fo:block>
                    <xsl:value-of select="$newline"/>
                </fo:block>

                <fo:block text-align="justify" >
                    <xsl:value-of select="/export/contactInfo"/>
                </fo:block>

                <fo:block>
                    <xsl:value-of select="$newline"/>
                </fo:block>

                <fo:table  border-width="0" margin-bottom="3cm" >
                    <fo:table-column column-width="5.6cm" />
                    <fo:table-column column-width="5.6cm" />
                    <fo:table-column column-width="5.6cm" />
                    <fo:table-body>
                        <fo:table-row>
                            <fo:table-cell display-align="after">
                                <fo:block text-align="left">
                                    Occupation <xsl:value-of select="/export/occupation"/>
                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell display-align="before">
                                <fo:block text-align="center">
                                    Signature <fo:external-graphic src='url({$signatureURL})'/>
                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell display-align="after">
                                <fo:block text-align="left">
                                    Name <xsl:value-of select="/export/name"/>
                                </fo:block>
                            </fo:table-cell>
                        </fo:table-row>
                    </fo:table-body>
                </fo:table>

            </fo:block>

        </fo:flow>
    </xsl:template>

</xsl:stylesheet>

Output file in .doc format
Code on pastebin
脚注的问题是 - 当我试图将内容放入脚注时(放置的 fo:block 语句而不是前一个代码部分中的最后一个 fo:table ):

...
<fo:block>
            The quick brown fox jumps over a lazy dog. The quick brown fox jumps over
            a lazy dog. The quick brown fox jumps over a lazy dog.
        <fo:footnote>
            <fo:inline baseline-shift="super"  font-size="10pt">
                (*)
            </fo:inline>
            <fo:footnote-body>
                <fo:block>
                    * This is the first footnote
                </fo:block>
            </fo:footnote-body>
        </fo:footnote>
            The quick brown fox jumps over a lazy dog. The quick brown fox jumps over
            a lazy dog.
 </fo:block>
</fo:flow>
</xsl:template>
</xsl:stylesheet>

输出结果如下:

...
敏捷的棕色狐狸跳过一只懒惰的狗。敏捷的棕色狐狸跳过一只懒惰的狗。敏捷的棕色狐狸跳过一只懒惰的狗。 (*) 敏捷的棕色狐狸跳过一只懒惰的狗。敏捷的棕色狐狸跳过一只懒惰的狗。
* 这是第一个脚注

脚注字符串紧跟在前一个文本之后,而不是在页面底部

【问题讨论】:

  • 包含 XML 文件,以便其他人提供解决方案。
  • 输出文件为 .doc 格式。在第一个代码块之后添加了指向输出文件和 xsl 代码的链接

标签: xslt xsl-fo


【解决方案1】:

margin-bottom 属性表示您希望在表格下方留一个空格。它与将对象放置在页面底部无关。 如果您希望表格出现在页面底部,有 2 个选项:

  1. 将其插入region-after area,而不是正文区域。
  2. 将其包装在具有绝对位置的block-container 中。

【讨论】:

    【解决方案2】:

    我将我想要的内容放在页面底部的一个脚注结构中,它位于一个带有空内联引用的空块中。让格式化程序担心页面底部在哪里。我告诉我的学生,对于文档最后一页底部的法律免责声明等内容,这是一种合适的方法。

    绝对定位块容器的问题在于,如果它的尺寸与主体重叠,那么主体内容可能会覆盖它。如果针对该内容缩小正文内容,则需要适应页面几何形状中的不同区域。

    我发现把它放在脚注中是最简单的。

    【讨论】:

    • 脚注的问题是格式化程序认为页面底部是最后写入的下一行...我添加了脚注构造函数和输出结果。
    • 不适用于我测试的任何格式化程序。只需使用您在上面编写的块并使用 RenderX 和 Apache FOP,都将脚注正确地放在页面底部。也许是您使用的 FO 引擎?
    • 我也在使用 apache fop 1.1 版格式化程序(org.apache.xmlgraphics)
    猜你喜欢
    • 2013-07-18
    • 2015-12-18
    • 1970-01-01
    • 2014-04-01
    • 2011-06-02
    • 2015-08-23
    • 1970-01-01
    • 2015-02-01
    • 2013-01-01
    相关资源
    最近更新 更多