如何检测文档的最后一页? [英] How to detect the last page of the document?
问题描述
我使用 FOP 从 xml 文件创建 pdf 文件.我想在 pdf 的最后一页上显示一些内容.问题是我不知道需要多少页来显示内容,所以我怎么知道我在实际的最后一页?(每个page-sequence可以根据内容的大小生成1+个文档页面)
I create pdf files from xml files with FOP. I would like to display something on the last page of the pdf. The thing is I can not know how many pages are needed to display the content so how can I know I am on the actual last page? (each page-sequence can generate 1+ document pages according to the size of the content)
谢谢.
推荐答案
您可以为一般页面布局和页眉页脚指定条件页面母版 (fo:static-content):http://www.w3.org/TR/xsl/#page-position一个>
You can specify conditional page masters for general page layout and headers and footers (fo:static-content): http://www.w3.org/TR/xsl/#page-position
用法:
1.) 在您的 fo:layout-master-set 中,定义您想要拥有的不同页面母版.例如,一个普通的页面母版和最后一页的一个应该是不同的.
1.) In your fo:layout-master-set, define the different page masters you want to have. For example, a normal page master and one for the last page which is supposed to be different.
普通页面母版示例:
<fo:simple-page-master master-name="page-master-161302528-normal"
margin-left="2cm" margin-right="2cm" page-height="297mm"
page-width="210mm">
<fo:region-body margin-top="3.5cm" margin-bottom="41mm"
column-count="1" column-gap="0.50in" />
<fo:region-before region-name="normal-header"
overflow="visible" extent="2cm" />
<fo:region-after region-name="normal-footer"
overflow="visible" extent="40mm" precedence="true" />
</fo:simple-page-master>
2.) 在 fo:layout-master-set 中定义一个 fo:page-sequence-master - 在这里添加条件:
2.) Define a fo:page-sequence-master inside your fo:layout-master-set - here you add the conditions:
<fo:page-sequence-master master-name="page-master-161302528">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="page-master-161302528-last" page-position="last"/>
<fo:conditional-page-master-reference master-reference="page-master-161302528-normal" />
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
3.) 在您的文档中,为您定义的 fo 元素(fo:static-content 和 fo:page-sequence)提供主参考 - 如果相应的主处于活动状态,则应呈现相应的元素.fo:static-content 元素必须根据上面的 fo:simple-page-master 命名一个 region-name 作为 flow-name 属性.
3.) In your document, give a master reference for the fo elements you define (fo:static-content and fo:page-sequence) - the respective elements should be rendered if the respective master is active. fo:static-content elements have to name a region-name as a flow-name attribute well, according to the above fo:simple-page-master.
示例:
<fo:page-sequence force-page-count="no-force"
master-reference="page-master-161302528" initial-page-number="auto"
format="1">
<fo:static-content flow-name="normal-header">...</fo:static-content>
</fo:page-sequence>
在这个整体示例中,特定页面页眉和页脚的选择是通过正常页眉/页脚(例如正常页眉")和最后一页页眉/页脚(例如最后一页标题").
In this overall example, the selection of a specific page header and footer is made by means of a flow-name that is different for normal headers / footers (e.g. "normal-header") and last-page headers / footers (e.g. "last-page-header").
这篇关于如何检测文档的最后一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!