问题
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)
Thanks.
回答1:
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
Usage:
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.
Example for the normal page master:
<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.) 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.) 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.
Example:
<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").
来源:https://stackoverflow.com/questions/13299809/how-to-detect-the-last-page-of-the-document