【问题标题】:Prevent blank page on last side in xsl fo防止xsl fo中最后一面的空白页
【发布时间】:2014-09-24 07:02:39
【问题描述】:

我正在使用 xsl fo 和 apache fop 来生成 pdf 文档。我有不同的页面序列(封面、目录、印记和“主要内容”)。

在主要内容中,我处理来自 xml 文件的数据,这很好。

在主要内容的开头,我开始计算页面并将其显示在底部/右侧。有了这个我遇到了一个问题,它在“主要内容”之前显示一个空白页面,我可以通过在之前的页面序列上添加“force-page-count =“no-force”来解决这个问题。

但是我在主内容序列之后有一个空白页,知道我该如何解决这个问题吗?

主要内容之前的页面序列:

<fo:page-sequence master-reference="imprint" force-page-count="no-force">
...
</fo:page-sequence>

主要内容:

<fo:page-sequence master-reference="per-Gruppe" initial-page-number="1">
                <fo:static-content flow-name="header">
                    <xsl:call-template name="doc-header" match=""/>
                    <fo:block/>
                </fo:static-content>
                <fo:static-content flow-name="footer">
                    <xsl:call-template name="doc-footer"/>
                    <fo:block/>
                </fo:static-content>
                <fo:flow flow-name="xsl-region-body">
                    <xsl:for-each select="//lb">
                        <xsl:call-template name="Kapitel" select="name"/>
                        <xsl:for-each select="per-group/pe">
                            <xsl:call-template name="st.Table" select="."/>
                        </xsl:for-each>
                        <xsl:for-each select="cu-group/cu">
                            <xsl:call-template name="st.Table" select="."/>
                        </xsl:for-each>
                        <xsl:if test="position()=last()">
                            <fo:block id="lastpage"/>
                        </xsl:if>
                    </xsl:for-each>
                </fo:flow>
            </fo:page-sequence>

有什么建议吗?

谢谢。

【问题讨论】:

    标签: xslt xslt-1.0 xsl-fo apache-fop


    【解决方案1】:

    好的,我解决了。我执行以下步骤。

    1. 我将 for each 循环放在页面序列之外。
    2. 然后我用 xsl:choose 将序列括起来,在 xsl:choose 中我检查位置
    3. 结果我调用模板页面序列和->“st.table”模板
    4. 在模板(st.table)中,我检查结果,如果它是最后一个位置,我设置最后一页,我阻止设置 page-break-after 属性(这就是我在结束)

    页面序列:

    <xsl:for-each select="//lb">
                    <xsl:choose>
                        <xsl:when test="position() = 1">
                            <fo:page-sequence master-reference="per-Gruppe" initial-page-number="1">
                                ...
                            </fo:page-sequence>
                        </xsl:when>
                        <xsl:otherwise>
                            <fo:page-sequence master-reference="per-Gruppe">
                                ...
                                <fo:flow flow-name="xsl-region-body">
                                    ...
                                    <xsl:for-each select="cu-group/cu">
                                        <xsl:call-template name="st.Table" select=".">
                                            <xsl:with-param name="last_pos" select="$last_pos" />
                                        </xsl:call-template>
                                    </xsl:for-each>
                                </fo:flow>
                            </fo:page-sequence>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:for-each>
    

    模板:

    <xsl:template name="st.Table" match=".">
            <xsl:param name="last_pos" select="false()" />
            ...
            <xsl:if test="$last_pos">
                <fo:block id="lastpage"/>       
            </xsl:if>
            <xsl:if test="$last_pos=false()">
                <fo:block page-break-after="always" />
            </xsl:if>
        </xsl:template>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 2015-12-18
      • 1970-01-01
      • 2011-12-29
      • 2015-02-01
      • 2013-01-01
      相关资源
      最近更新 更多