如何在PDF报表中使用xslt显示页码(第N个,共N个) [英] How to show page number (N of N) using xslt in PDF Report

查看:80
本文介绍了如何在PDF报表中使用xslt显示页码(第N个,共N个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XSLT生成PDF报告.我的要求是在报表的页脚处以N页的第N页格式显示页码(例如,第1页,共3页).对于静态值,它可以正常工作,并在每页上重复.由于报告中的页面总数未知,并且会更改运行时间,因此我将如何完成此任务.

I am using XSLT to generate PDF report. My requirements are to display page number in the format of Page N of N (e.g.Page 1 of 3) at the footer of the report. For static values it works fine and it repeats on each page. As total number of pages in the report are not known and it changes run time, so how I will accomplish this task.

我的XSLT代码段

<xsl:template name="footerall">
<xsl:variable name="maxwidth" select="7.07000" />
<fo:static-content flow-name="xsl-region-after">
<fo:block>
<xsl:variable name="tablewidth29" select="$maxwidth * 1.00000" />
<xsl:variable name="sumcolumnwidths29" select="0.04167 + 1.56250 + 0.04167" />
<xsl:variable name="factor29">
<xsl:choose>
<xsl:when
test="$sumcolumnwidths29 &gt; 0.00000 and $sumcolumnwidths29 &gt; $tablewidth29">
<xsl:value-of select="$tablewidth29 div $sumcolumnwidths29" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="1.000" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="defaultcolumns29" select="1" />
<xsl:variable name="defaultcolumnwidth29">
<xsl:choose>
<xsl:when test="$factor29 &lt; 1.000">
<xsl:value-of select="0.000" />
</xsl:when>
<xsl:when test="$defaultcolumns29 &gt; 0">
<xsl:value-of
select="($tablewidth29 - $sumcolumnwidths29) div $defaultcolumns29" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0.000" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="columnwidth29_0" select="$defaultcolumnwidth29" />
<xsl:variable name="columnwidth29_1" select="1.56250 * $factor29" />
<fo:table width="{$tablewidth29}in" border-collapse="separate"
border-separation="0.04167in" color="black" display-align="center">
<fo:table-column column-width="{$columnwidth29_0}in" />
<fo:table-column column-width="{$columnwidth29_1}in" />
<fo:table-body>
<fo:table-row>
<fo:table-cell number-columns-spanned="2"
padding-top="0.00000in" padding-bottom="0.00000in" padding-left="0.00000in"
padding-right="0.00000in">
<fo:block padding-top="1pt" padding-bottom="1pt">
<fo:block text-align="center" space-before.optimum="-8pt">
<fo:leader leader-length="100%" leader-pattern="rule"
rule-thickness="1pt" color="black" />
</fo:block>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell
font-size="inherited-property-value(&apos;font-size&apos;) - 2pt"
text-align="left" padding-top="0.00000in" padding-bottom="0.00000in"
padding-left="0.00000in" padding-right="0.00000in">
<fo:block padding-top="1pt" padding-bottom="1pt">
<fo:inline font-family="Courier" font-size="10px">
<xsl:value-of select="$My XPath to varaible" />
</fo:inline>
<fo:inline font-family="Courier" font-size="10px">
<xsl:text> - </xsl:text>
<xsl:text>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</xsl:text>
<xsl:text>Page 1 of 1</xsl:text>
</fo:inline>
<fo:inline font-family="Courier" font-size="10px">
<xsl:value-of select="$My XPath to varaible" />
</fo:inline>
</fo:block>
</fo:table-cell>
<fo:table-cell
font-size="inherited-property-value(&apos;font-size&apos;) - 2pt"
text-align="right" padding-top="0.00000in" padding-bottom="0.00000in"
padding-left="0.00000in" padding-right="0.00000in">
<fo:block padding-top="1pt" padding-bottom="1pt" />
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
</fo:static-content>
</xsl:template>

我将用一个变量替换字符串(第1页,共1页),但如何处理.

I will replace the string (Page 1 of 1) by a variable but how to handle this.

请帮助我.

推荐答案

我按照以下说明解决了我的问题.

I solved my problem by following below instructions.

在该区域的末尾放置一个带有ID的格式化对象.然后,您可以对出现在文档最后一页上的带标签的块执行"a"操作.标记的外观如下:

Put a formatting object with an id at the end of the area. You can then do a to the labeled block that appears on the last page of the document. Here's how the markup looks:

<fo:flow flow-name="xsl-region-body">
... Lots and lots of content here
<fo:block id="TheVeryLastPage"> </fo:block>
</fo:flow>

该代码创建一个ID为TheVeryLastPage(该值不太可能被任何人使用)的块,现在您可以引用该ID来获取文档最后一页的页码.这是该区域中内容的外观:

The code creates a block with an id of TheVeryLastPage (a value that's unlikely to be used by anyone), and now you can refer to that id to get the page number of the last page of the document. Here's how the content in the area should look:

<fo:block text-align="end">
Page <fo:page-number/> of 
<fo:page-number-citation 
ref-id="TheVeryLastPage"/>
</fo:block>

当FOP格式化此标记时,它会生成类似第2页,共5页"的内容.

When FOP formats this markup, it generates something like "Page 2 of 5".

我的参考URL是: http://www.ibm.com/developerworks/xml/tutorials/x-xslfo2/section4.html

这篇关于如何在PDF报表中使用xslt显示页码(第N个,共N个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆