如何检测文件的最后一页? [英] How to detect the last page of the document?

查看:95
本文介绍了如何检测文件的最后一页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用FOP从xml文件创建pdf文件. 我想在pdf的最后一页上显示一些内容. 问题是我不知道显示内容需要多少页,所以我怎么知道我在实际的最后一页上? (每个页面顺序可以根据内容的大小生成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:simple-page-master,fo:static-content元素必须很好地将区域名称命名为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>

在此总体示例中,特定流页眉和页脚的选择是通过流名称进行的,该流名称对于普通页眉/页脚(例如"normal-header")和最后一页页眉/页脚(例如最后一页标题".

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屋!

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