XSL-FO不同的页眉/页脚(取决于页面位置) [英] XSL-FO Different header/footer depending on page-position

查看:66
本文介绍了XSL-FO不同的页眉/页脚(取决于页面位置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是XSL-FO的一个非常普遍的问题:我尝试建立一个具有明确规格的帐单:

This might be a quite common problem with XSL-FO: I try to build a billing which has clear specifications:

  1. 主标题":每页(文本,徽标和条形码)
  2. 子标题" :(客户数据)

  1. "Main Header": on every page (Text, Logo and Barcode)
  2. "Sub Header": (Customer Data)

->在第一页上,此块应为页面高度的10%左右

-> On the first page this block should be about 10% of the pages height

->在所有其他页面上,此区块应小一半左右,所以可以说5%

-> On all the others page this block should be about the half smaller, so lets say 5%

最后一页页脚":位于课程的最后一页(总数和签名)

"Last-Page Footer": just on the last page of course (Total amount and signatures)

每页页脚":仅用于打印日期

"Every-page Footer": just for the printing date

正文":帐单的内容(每个位置)应自动在所有页眉和页脚之间流动

"Body": the content of the billing (every position) should flow in between of the all headers and footers automatically

所以我知道可以通过使用属性page-position来实现一些要点:

So i know that some points can be realised by using the attribute page-position:

<fo:page-sequence-master master-name="masterSequenceName1">
<fo:repeatable-page-master-alternatives>
  <fo:conditional-page-master-reference master-reference="masterNamePageFirst1" page-position="first"></fo:conditional-page-master-reference>
  <fo:conditional-page-master-reference master-reference="masterNamePageLast1"  page-position="last"></fo:conditional-page-master-reference>
  <fo:conditional-page-master-reference master-reference="masterNamePageAny"    page-position="any"></fo:conditional-page-master-reference>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>

我可以为每种情况定义区域,但是存在以下问题:

I can define the regions for each of this cases but having these issues:

  1. 如果第一页是最后一页(仅一页),则最后一页的页脚将不会出现.知道页面位置可以具有值"only",因此也可以为此设置一个静态内容.但是我仍然会有两个内容相同的块,每当我要编辑此部分时,都必须对其进行两次更改.
  2. 通常可以通过区域之前设置主标头,并引用page-position ="any"(这是标准方法),但是以某种方式,这对我不起作用.我只是在不是第一页或最后一页的页面上获取标题.这实际上不应该是page-position ="rest"的理想功能吗?

推荐答案

A note in the definition of the page-position property states that (emphasis added):

这些值中的几个可以同时为真;例如,任何" 当第一个"和最后一个"都是 真的.因此,必须订购 fo:conditional-page-master-references,以便进行最少的包容性测试 在更具包容性的测试之前执行,这也是正确的.

Several of these values can be true simultaneously; for example, 'any' is always true and 'only' is true when both 'first' and 'last' are true. For that reason, it is necessary to order the fo:conditional-page-master-references so that the least inclusive test is performed before the more inclusive test which are also true.

换句话说,被选为构建页面的conditional-page-master-reference条件评估为true的第一个,并且甚至不考虑以下引用.

In other words, the conditional-page-master-reference that is elected to build a page is the first one whose conditions evaluate to true, and following references are not even taken into consideration.

要记住的另一个重要点是条件(page-positionodd-or-evenblank-or-not-blank)选择页面母版,而不是特定的静态内容.

Another important point to remember is that conditions (page-position, odd-or-even, blank-or-not-blank) select a page master, not a specific static content.

因此,请看您的问题:

1.如果第一页是最后一页(仅一页),则最后一页的页脚 不会出现.

1. If the first page is the last ( only one page), the last page footer won't appear.

之所以会发生这种情况,是因为在您的示例中,适用于第一页和唯一页的第一个conditional-page-master-reference是指向"masterNamePageFirst1"的那个(我想,因为它不在问题中),其后有一个区域仅映射了每页页脚".

this happens because the first conditional-page-master-reference applicable to the first and only page is, in your example, the one pointing to "masterNamePageFirst1" which (I guess, as it is not in the question) has a region-after into which only the "every page footer" is mapped.

知道页面位置可以具有"only"值,这是可能的 也将为此设置静态内容.但是我仍然会 两个具有相同内容的块,每当我要编辑此块时 部分,我将不得不更改两次.

Knowing that page-position can have the value "only", a possiblity would be to set a static-content for this, too. But still I would have two blocks of the same content and whenever I wanted to edit this part, I would have to change it twice.

您不必重复两次相同的内容:您可以将其放入命名模板,然后从两个静态内容中调用该模板.

You don't have to repeat twice the same content: you can put it into a named template, and call that template from inside the two static contents.

2.通常,可以通过一个区域来设置主标头,然后在前面加上一个 引用page-position ="any"(这是标准),但是不知何故 这对我不起作用.我只是在页面的标题 不是第一个或最后一个.这实际上不是所需的功能吗 的page-position ="rest" ?

2. The main header normally can be set by a region-before with a reference to page-position="any" (which is the standard), but somehow this won't work for me. I'm just getting the header at pages which aren't first or last. Shouldn't this actually be the desired function of page-position="rest"?

静态内容已映射到区域:检查第一页和最后一页的页面母版中是否确实存在该区域.

Static content is mapped to a region: check whether that region is actually present in the page masters for the first and for the last page.

完整的示例

以下是一个示例,该示例使用不同页面几何,也显示了根据页面位置的不同页眉/页脚 ="http://www.w3.org/TR/xsl/#fo_marker" rel ="nofollow"> fo:marker s

Here is an example that shows both different page geometry for only/first/rest/any page and different headers/footers according to the page position using fo:markers and fo:retrieve-markers.

我使用FOP 1.1进行了测试,结果pdf应符合您的规格.

I tested it with FOP 1.1, and the resulting pdf should conform to your specifications.

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <fo:layout-master-set>
        <fo:simple-page-master master-name="singlePage" margin="1cm">
            <fo:region-body margin-top="5cm" margin-bottom="4cm" background-color="#FFFFAA"/>
            <fo:region-before extent="4cm" background-color="#AAFFFF"/>
            <fo:region-after extent="3cm" background-color="#FFAAFF" display-align="after"/>
        </fo:simple-page-master>
        <fo:simple-page-master master-name="firstPage" margin="1cm">
            <fo:region-body margin-top="5cm" margin-bottom="2cm" background-color="#FFFFAA"/>
            <fo:region-before extent="4cm" background-color="#AAFFFF"/>
            <fo:region-after extent="1cm" background-color="#FFAAFF" display-align="after"/>
        </fo:simple-page-master>
        <fo:simple-page-master master-name="middlePage" margin="1cm">
            <fo:region-body margin-top="2cm" margin-bottom="2cm" background-color="#FFFFAA"/>
            <fo:region-before extent="1cm" background-color="#AAFFFF"/>
            <fo:region-after extent="1cm" background-color="#FFAAFF" display-align="after"/>
        </fo:simple-page-master>
        <fo:simple-page-master master-name="lastPage" margin="1cm">
            <fo:region-body margin-top="2cm" margin-bottom="4cm" background-color="#FFFFAA"/>
            <fo:region-before extent="1cm" background-color="#AAFFFF"/>
            <fo:region-after extent="3cm" background-color="#FFAAFF" display-align="after"/>
        </fo:simple-page-master>
        <fo:page-sequence-master master-name="allPages">
            <fo:repeatable-page-master-alternatives>
                <fo:conditional-page-master-reference page-position="only" master-reference="singlePage"/>
                <fo:conditional-page-master-reference page-position="first" master-reference="firstPage"/>
                <fo:conditional-page-master-reference page-position="rest" master-reference="middlePage"/>
                <fo:conditional-page-master-reference page-position="last" master-reference="lastPage"/>
            </fo:repeatable-page-master-alternatives>
        </fo:page-sequence-master>
    </fo:layout-master-set>
    <fo:page-sequence master-reference="allPages">
        <!--
            header
        -->
        <fo:static-content flow-name="xsl-region-before" font-size="90%">
            <!-- main header on every page -->
            <fo:block>Text, logo, barcode</fo:block>
            <!-- sub header -->
            <fo:retrieve-marker retrieve-class-name="subHeader" retrieve-position="first-starting-within-page"/>
        </fo:static-content>
        <!--
            footer
        -->
        <fo:static-content flow-name="xsl-region-after" font-size="90%">
            <!-- special footer -->
            <fo:retrieve-marker retrieve-class-name="footer" retrieve-position="first-starting-within-page"/>
            <!-- common footer on every page -->
            <fo:block>printing date dd/mm/yyyy</fo:block>
        </fo:static-content>
        <!--
            document body
        -->
        <fo:flow flow-name="xsl-region-body">
            <!-- empty blocks with markers for the header -->
            <fo:block>
                <!-- sub header for the first page -->
                <fo:marker marker-class-name="subHeader">
                    <fo:block>LARGE SUB HEADER</fo:block>
                </fo:marker>
            </fo:block>
            <fo:block>
                <!-- sub header for the not-first pages -->
                <fo:marker marker-class-name="subHeader">
                    <fo:block>small sub header</fo:block>
                </fo:marker>
            </fo:block>
            <!-- normal content -->
            <!-- 
                YOUR REAL CONTENT GOES HERE 
                (I just put some blocks with page breaks to produce a few pages)
            -->
            <fo:block break-after="page">Long sequence with many pages ...</fo:block>
            <fo:block break-after="page">... bla bla bla ...</fo:block>
            <fo:block>... the end</fo:block>
            <!-- empty block with marker for the footer -->
            <fo:block>
                <!-- footer for the last page -->
                <fo:marker marker-class-name="footer">
                    <fo:block>TOTAL AMOUNT $$$ AND SIGNATURES</fo:block>
                </fo:marker>
            </fo:block>
       </fo:flow>
    </fo:page-sequence>
</fo:root>

这篇关于XSL-FO不同的页眉/页脚(取决于页面位置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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