xsl-fo 删除第一页的页码

Posted

技术标签:

【中文标题】xsl-fo 删除第一页的页码【英文标题】:xsl-fo remove page number from first page 【发布时间】:2021-04-24 00:56:48 【问题描述】:

新手问题,但我真的找不到适用于我的 pdf 的 awenser。 我想让我的页码从第 2 页开始,我该怎么做?

这是我的 xsl 文件

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:template match="catalog">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
            <fo:layout-master-set>
                <fo:simple-page-master master-name="A4" page- page->
                    <fo:region-body margin="1in" background-color="#f2f2f2"/> 
                    <fo:region-before extent="1in" background-color="#dadada"  border-before-style ="solid"/>
                    <fo:region-after extent="1in" background-color="#c1c1c1 "  border-after-style  ="solid"/>
                    <fo:region-start extent="1in" background-color="#c1c1c1 "/>
                    <fo:region-end extent="1in" background-color="#c1c1c1"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="A4" initial-page-number="1">
        
        <fo:static-content flow-name="xsl-region-start">
             <fo:block>
                <xsl:text>BEST MUSIC</xsl:text>
            </fo:block>
            </fo:static-content>
            
                <fo:static-content flow-name="xsl-region-end">
             <fo:block>
                <xsl:text>CATALOG</xsl:text>
            </fo:block>
            </fo:static-content>
            
               <fo:static-content flow-name="xsl-region-after">
                <fo:block text-align="center">
                    Page <fo:page-number/>
                    of <fo:page-number-citation ref-id="terminator"/>
                </fo:block>
            </fo:static-content>
     
                <fo:flow flow-name="xsl-region-body">
                        <fo:table>
                        <fo:table-column column- />
                        <fo:table-column column- />
                        <fo:table-column column- />
                        <fo:table-column column- />
                        <fo:table-column column- />
                        <fo:table-column column- />
                        <fo:table-column column- />
                            <fo:table-header border="1 solid black">
                                <fo:table-row background-color="lightyellow" border="1 solid black">
                                    <fo:table-cell>
                                        <fo:block font-weight="bold">Title</fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell>
                                        <fo:block font-weight="bold">Artist </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell>
                                        <fo:block font-weight="bold">Company</fo:block>
                                    </fo:table-cell>
                                        <fo:table-cell>
                                        <fo:block font-weight="bold">Country</fo:block>
                                    </fo:table-cell>
                                        <fo:table-cell>
                                    <fo:block font-weight="bold">Year</fo:block>
                                </fo:table-cell>
                                        <fo:table-cell>
                                    <fo:block font-weight="bold">Price</fo:block>
                                </fo:table-cell>
                                    
                                </fo:table-row>
                            </fo:table-header>
                            <xsl:for-each select="cd">
                                <fo:table-body border="1 dotted black">
                                
                                    <fo:table-row>
                                        <fo:table-cell>
                                            <fo:block>
                                                <xsl:value-of select="title"/> 
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell>
                                            <fo:block>
                                                <xsl:value-of select="artist"/>
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell>
                                            <fo:block>
                                                <xsl:value-of select="company"/>
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell>
                                            <fo:block>
                                            <xsl:value-of select="country"/>
                                            </fo:block>
                                        </fo:table-cell>
                                            <fo:table-cell>
                                            <fo:block>
                                                <xsl:value-of select="year"/> 
                                            </fo:block>
                                        </fo:table-cell>
                                            <fo:table-cell>
                                            <fo:block>
                                                <xsl:value-of select="price"/> 
                                            </fo:block>
                                        </fo:table-cell>
                                        
                                    </fo:table-row>
                                </fo:table-body>
                            </xsl:for-each>
                        </fo:table>
                           <fo:block id="terminator"></fo:block>
                </fo:flow>
                </fo:page-sequence>
        </fo:root>
    </xsl:template>
</xsl:stylesheet>

我希望页码保留在页脚部分。 [![输入图像当前输出:][1]][1] :[![输入图像所需的输出][2]][2]

电流输出[1]:https://i.stack.imgur.com/JN3ar.png 期望的输出[2]:https://i.stack.imgur.com/paCVh.png

【问题讨论】:

【参考方案1】:

您的页脚来自&lt;fo:static-content flow-name="xsl-region-after"&gt;。每个页面都使用单个fo:simple-page-master,因此每个页面都有页脚。

您可以为第一页添加第二个fo:simple-page-master,该页面要么没有fo:region-after,要么具有不同region-name 值的fo:region-after

<fo:simple-page-master master-name="First" page- page->
  <fo:region-body margin="1in" background-color="#f2f2f2"/> 
  <fo:region-before extent="1in" background-color="#dadada"  border-before-style ="solid" />
  <fo:region-after region-name="First-footer" extent="1in" background-color="#c1c1c1 "  border-after-style  ="solid"/>
  <fo:region-start extent="1in" background-color="#c1c1c1 "/>
  <fo:region-end extent="1in" background-color="#c1c1c1"/>
</fo:simple-page-master>

要将fo:simple-page-master 用于第一页,请添加一个fo:page-sequence-master,为第一页选择正确的fo:simple-page-master

<fo:page-sequence-master master-name="PageMaster">
  <fo:repeatable-page-master-alternatives>
    <fo:conditional-page-master-reference master-reference="First" page-position="first" />
    <fo:conditional-page-master-reference master-reference="A4" />
  </fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>

您的fo:page-sequence 应该引用fo:page-sequence-master 而不是直接引用固定的fo:simple-page-master

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

另见:

https://www.w3.org/TR/xsl11/#page-position https://www.w3.org/TR/xsl11/#fo_page-sequence-master https://www.w3.org/TR/xsl11/#fo_region-after https://***.com/a/65701865/4092205 https://***.com/a/53204584/4092205 https://***.com/a/28382375/4092205

【讨论】:

你能分享整个xsl文件吗?我试图插入逻辑,但我可以使用一个例子,请 我没有创建文件,只是示例标记。在***.com/a/65019711/4092205、***.com/a/58343013/4092205 和***.com/a/28382375/4092205 的答案中有文档可能会有所帮助。 ***.com/a/53204584/4092205也有一个与您非常相似的问题@ 谢谢,我明天早上去看看

以上是关于xsl-fo 删除第一页的页码的主要内容,如果未能解决你的问题,请参考以下文章

Word中页码及目录的制做方法

vue框架,使用pagination组件进行分页时 分页不在第一页的时候保存了 筛选记录,然后f5刷新又到第一页了,到了onCurrentChange改变分页的函数改变了

jqgrid删除之后怎么回到第一页

怎么将word中第二页设置为第一页

word页码怎么从指定页开始设置

如何为 xsl-fo 中的每个页面添加页眉和页脚以生成 pdf