Apache fop,XSL FO:偶尔在页面序列的流末尾添加空页(不是最后一个)

时间:2017-04-26 16:25:28

标签: xsl-fo apache-fop

使用apache-fop 1.0也尝试了2.1具有相同的行为。

我的问题:

  • 为什么会生成空白页?
  • 页面编号如何如此 奇怪的是第4页,共3页?
  • 如何在保留的同时省略空白页面 页面编号?

情景:

使用以下XSL fop有时会在页面流的末尾插入一个空的页面。这也导致奇怪的页面编号,如第4页,共3页

这是3个不同的页面序列,每个序列的页面编号应该以1开头。第一个应该只添加封面页。第二个页面序列应该在第一页,最后一页和其他页面上使用不同的页脚呈现一些表格数据。第三个页面序列应该表示类似于页面序列二的副本,具有相同的输出但实际上具有略微不同的页眉和/或页脚。

但是,每个序列末尾的都会插入一个空的空白页 - 除了最后一个页面序列

每个页面序列本身(其他注释掉的)工作正常,没有生成空页。

我的XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                version="1.0"
                xsi:schemaLocation="http://www.w3.org/1999/XSL/Format http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop/src/foschema/fop.xsd?view=co">


    <xsl:template match="/">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

            <fo:layout-master-set>
                <fo:simple-page-master master-name="A4-cover"
                                       page-width="210mm" page-height="297mm" margin="1cm">
                    <fo:region-body region-name="body"/>
                </fo:simple-page-master>

                <fo:simple-page-master master-name="A4-first"
                                       page-width="210mm" page-height="297mm" margin="1cm">
                    <fo:region-body region-name="body" space-before="11cm" space-after="3cm"/>
                    <fo:region-before region-name="header-first" extent="11cm"/>
                    <fo:region-after region-name="footer-first" extent="3cm"/>
                </fo:simple-page-master>


                <fo:simple-page-master master-name="A4-other"
                                       page-width="210mm" page-height="297mm" margin="1cm">
                    <fo:region-body region-name="body" space-before="3cm" space-after="5cm"/>
                    <fo:region-before region-name="header-other" extent="3cm"/>
                    <fo:region-after region-name="footer-other" extent="5cm"/>
                </fo:simple-page-master>


                <fo:simple-page-master master-name="A4-last"
                                       page-width="210mm" page-height="297mm" margin="1cm">
                    <fo:region-body region-name="body" space-before="3cm" space-after="5cm"/>
                    <fo:region-before region-name="header-last" extent="3cm"/>
                    <fo:region-after region-name="footer-last" extent="5cm"/>
                </fo:simple-page-master>


                <fo:page-sequence-master master-name="A4-multi">
                    <fo:repeatable-page-master-alternatives>
                        <fo:conditional-page-master-reference page-position="first" master-reference="A4-first"/>
                        <fo:conditional-page-master-reference page-position="rest" master-reference="A4-other"/>
                        <fo:conditional-page-master-reference page-position="last" master-reference="A4-last"/>
                    </fo:repeatable-page-master-alternatives>
                </fo:page-sequence-master>


                <fo:page-sequence-master master-name="A4-very-first">
                    <fo:repeatable-page-master-alternatives>
                        <fo:conditional-page-master-reference page-position="first" master-reference="A4-cover"/>
                        <fo:conditional-page-master-reference page-position="rest" master-reference="A4-other"/>
                    </fo:repeatable-page-master-alternatives>
                </fo:page-sequence-master>
            </fo:layout-master-set>



            <fo:page-sequence master-reference="A4-very-first" initial-page-number="1">
                <fo:flow flow-name="body">
                    <fo:block>just the first page</fo:block>
                </fo:flow>
            </fo:page-sequence>

            <fo:page-sequence master-reference="A4-multi" initial-page-number="1">

                <xsl:call-template name="header-first"/>
                <xsl:call-template name="header-other"/>
                <xsl:call-template name="header-last"/>

                <xsl:call-template name="footer-first"/>
                <xsl:call-template name="footer-other"/>
                <xsl:call-template name="footer-last"/>

                <xsl:call-template name="flow-1"/>
            </fo:page-sequence>


            <fo:page-sequence master-reference="A4-multi" initial-page-number="1">

                <xsl:call-template name="header-first"/>
                <xsl:call-template name="header-other"/>
                <xsl:call-template name="header-last"/>

                <xsl:call-template name="footer-first"/>
                <xsl:call-template name="footer-other"/>
                <xsl:call-template name="footer-last"/>
                <xsl:call-template name="flow-2"/>

            </fo:page-sequence>


        </fo:root>
    </xsl:template>

    <xsl:template name="flow-1">
        <fo:flow flow-name="body">
            <xsl:call-template name="item-table"/>
            <fo:block id="last-page-flow-1"></fo:block>
        </fo:flow>
    </xsl:template>

    <!-- just a copy of flow 1-->
    <xsl:template name="flow-2">
        <fo:flow flow-name="body">
            <xsl:call-template name="item-table"/>
            <fo:block id="last-page-flow-2"></fo:block>
        </fo:flow>
    </xsl:template>
    <!-- table -->
    <xsl:template name="item-table">
        <fo:table width="100%" border="1px solid black" table-layout="fixed">
            <fo:table-column column-width="proportional-column-width(1)"/>

            <fo:table-header>
                <fo:table-row border="1px solid red">
                    <fo:table-cell>
                        <fo:block>Item: header</fo:block>
                    </fo:table-cell>
                </fo:table-row>
            </fo:table-header>

            <fo:table-footer>
                <fo:table-row>
                    <fo:table-cell border="1px solid blue">
                        <fo:block>Item: footer</fo:block>
                    </fo:table-cell>
                </fo:table-row>
            </fo:table-footer>

            <fo:table-body>
                <xsl:apply-templates select="list"/>
            </fo:table-body>

        </fo:table>
    </xsl:template>
    <!-- row -->
    <xsl:template match="item">
        <fo:table-row>
            <fo:table-cell border-bottom="1px dashed black">
                <fo:block>
                    <xsl:value-of select="out"/>
                </fo:block>
            </fo:table-cell>
        </fo:table-row>
    </xsl:template>

    <!-- the different headers  -->
    <xsl:template name="header-initial">
        <fo:static-content flow-name="header-initial">
            <fo:table background-color="yellow" width="100%" table-layout="fixed">
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell height="4cm">
                            <fo:block>Header first page</fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:static-content>
    </xsl:template>
    <xsl:template name="header-first">
        <fo:static-content flow-name="header-first">
            <fo:table background-color="yellow" width="100%" table-layout="fixed">
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell height="11cm">
                            <fo:block>Header first page</fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:static-content>
    </xsl:template>
    <xsl:template name="header-other">
        <fo:static-content flow-name="header-other">
            <fo:table background-color="red" width="100%" table-layout="fixed">
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell height="3cm">
                            <fo:block>Header other pages</fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:static-content>
    </xsl:template>

    <xsl:template name="header-last">
        <fo:static-content flow-name="header-last">
            <fo:table background-color="blue" width="100%" table-layout="fixed">
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell height="3cm">
                            <fo:block>Header last page</fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:static-content>
    </xsl:template>
    <!-- the different footers  -->
    <xsl:template name="footer-initial">
        <fo:static-content flow-name="footer-initial">
            <fo:table background-color="orange" width="100%" table-layout="fixed">
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell height="106mm">
                            <fo:block>Footer initial page - ESR</fo:block>
                            <fo:block>P<fo:page-number/>/
                                <fo:page-number-citation-last ref-id="last-page-flow-1"/>
                                <fo:page-number-citation-last ref-id="last-page-flow-2"/>
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:static-content>
    </xsl:template>
    <xsl:template name="footer-first">
        <fo:static-content flow-name="footer-first">
            <fo:table background-color="yellow" width="100%" table-layout="fixed">
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell height="3cm">
                            <fo:block>Footer first page</fo:block>
                            <fo:block>Page
                                <fo:page-number/>
                                of
                                <fo:page-number-citation-last ref-id="last-page-flow-1"/>
                                <fo:page-number-citation-last ref-id="last-page-flow-2"/>
                                Pages
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:static-content>
    </xsl:template>
    <xsl:template name="footer-other">
        <fo:static-content flow-name="footer-other">
            <fo:table background-color="red" width="100%" table-layout="fixed">
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell height="5cm">
                            <fo:block>Footer other pages</fo:block>
                            <fo:block>Page
                                <fo:page-number/>
                                of
                                <fo:page-number-citation-last ref-id="last-page-flow-1"/>
                                <fo:page-number-citation-last ref-id="last-page-flow-2"/>
                                Pages
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>

        </fo:static-content>
    </xsl:template>

    <xsl:template name="footer-last">
        <fo:static-content flow-name="footer-last">
            <fo:table background-color="blue" width="100%" table-layout="fixed">
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell height="5cm">
                            <fo:block>Footer last page</fo:block>
                            <fo:block>Page<fo:page-number/>of
                                <fo:page-number-citation-last ref-id="last-page-flow-1"/>
                                <fo:page-number-citation-last ref-id="last-page-flow-2"/>
                                Pages
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:static-content>
    </xsl:template>
</xsl:stylesheet>

我的XML包含一些简单的数据

<list>

<item>
    <out>Test1</out>
</item>
<item>
    <out>Test2</out>
</item>
<item>
    <out>Test3</out>
</item>
<item>
    <out>Test4</out>
</item>
<item>
    <out>Test5</out>
</item>
<item>
    <out>Test6</out>
</item>
<item>
    <out>Test7</out>
</item>
<item>
    <out>Test8</out>
</item>
<item>
    <out>Test9</out>
</item>
<item>
    <out>Test10</out>
</item>

<item>
    <out>Test11</out>
</item>
<item>
    <out>Test12</out>
</item>
<item>
    <out>Test13</out>
</item>
<item>
    <out>Test14</out>
</item>
<item>
    <out>Test15</out>
</item>
<item>
    <out>Test16</out>
</item>
<item>
    <out>Test17</out>
</item>
<item>
    <out>Test18</out>
</item>
<item>
    <out>Test19</out>
</item>
<item>
    <out>Test20</out>
</item>

<item>
    <out>Test21</out>
</item>
<item>
    <out>Test22</out>
</item>
<item>
    <out>Test23 -- last on page-first</out>
</item>

<!-- max items on first page -->
<item>
    <out>Test24 -- first on page-other/page-last</out>
</item>
<item>
    <out>Test25</out>
</item>
<item>
    <out>Test26</out>
</item>
<item>
    <out>Test27</out>
</item>
<item>
    <out>Test28</out>
</item>
<item>
    <out>Test29</out>
</item>
<item>
    <out>Test30</out>
</item>

<item>
    <out>Test31</out>
</item>
<item>
    <out>Test32</out>
</item>
<item>
    <out>Test33</out>
</item>
<item>
    <out>Test34</out>
</item>
<item>
    <out>Test35</out>
</item>
<item>
    <out>Test36</out>
</item>
<item>
    <out>Test37</out>
</item>
<item>
    <out>Test38</out>
</item>
<item>
    <out>Test39</out>
</item>
<item>
    <out>Test40</out>
</item>

<item>
    <out>Test41</out>
</item>
<item>
    <out>Test42</out>
</item>
<item>
    <out>Test43</out>
</item>
<item>
    <out>Test44</out>
</item>
<item>
    <out>Test45</out>
</item>
<item>
    <out>Test46</out>
</item>
<item>
    <out>Test47</out>
</item>

<item>
    <out>Test48</out>
</item>

<item>
    <out>Test49</out>
</item>
<item>
    <out>Test50</out>
</item>
<item>
    <out>Test51</out>
</item>
<item>
    <out>Test52</out>
</item>
<item>
    <out>Test53</out>
</item>
<item>
    <out>Test54</out>
</item>

<item>
    <out>Test55</out>
</item>
<item>
    <out>Test56</out>
</item>
<item>
    <out>Test57 - last on page-other</out>
</item>

<item>
    <out>Test58 -first on page-last</out>
</item>

在页面序列二(蓝色)的最后一页之后的空页面(红色),

1 个答案:

答案 0 :(得分:3)

Gotit。页面序列的强制页面计数如果是&#34; auto&#34;如果下一个页面序列的初始页面编号为奇数,则强制它为偶数页面#34; w3c

因此,您的第三个页面序列的初始页面编号为1(奇数),但是第二个页面的最后一页实际上是5(如果我们省略了第一页,则为3)(也是奇数),因此一页将会添加,显然甚至没有把它当作最后(不好)。它将显示第3页(因为它是第4个) of 3 (因为引用的ID在第3页上)

解决方法是添加

force-page-count="no-force"

属性fo:page-sequence s

修改

如果您还有一个没有页眉或页脚的blank-or-not-blank="blank"条件页面主参考,那么在该添加的页面上不会显示页码。但我明白你根本没有这个。