gpt4 book ai didi

xslt - XSL-FO 根据页面位置不同的页眉/页脚

转载 作者:行者123 更新时间:2023-12-01 23:16:32 24 4
gpt4 key购买 nike

这可能是 XSL-FO 的一个非常常见的问题:我尝试构建一个具有明确规范的计费:

  1. “主标题”:在每个页面上(文本、 Logo 和条形码)
  2. “子标题”:(客户数据)

    -> 在第一页上,该 block 应约为页面高度的 10%

    -> 在所有其他页面上,这个 block 应该小一半左右,所以假设 5%

  3. “最后一页页脚”:当然就在最后一页(总金额和签名)

  4. “每页页脚”:仅用于打印日期

  5. “正文”:帐单内容(每个位置)应自动流入所有页眉和页脚之间

所以我知道有些点可以通过使用属性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>

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

  1. 如果第一页是最后一页(只有一页),则不会显示最后一页页脚。知道页面位置可以具有“仅”值,也可以为此设置静态内容。但我仍然会有两个相同内容的 block ,每当我想编辑这部分时,我都必须更改它两次。
  2. 主标题通常可以通过引用 page-position="any"(这是标准)来设置,但不知何故这对我不起作用。我只是在不是第一个或最后一个页面上获取标题。这实际上不应该是 page-position="rest"所需的功能吗?

最佳答案

page-position 定义中的注释属性指出(强调):

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的,并且以下引用是甚至没有考虑到。

要记住的另一个重要点是条件(页面位置奇数或偶数空白或非空白 ) 选择页面母版,而不是特定的静态内容

所以,看看你的问题:

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

发生这种情况是因为,在您的示例中,适用于第一个也是唯一页面的第一个 conditional-page-master-reference 是指向 “masterNamePageFirst1” 的页面(我猜,因为它不在问题中)有一个区域,之后仅映射“每页页脚”。

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.

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

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"?

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

编辑:完整示例

这里是一个示例,使用 fo:markers 显示仅/第一页/休息/任何页面的不同页面几何形状以及根据页面位置的不同页眉/页脚fo:retrieve-markers .

我用 FOP 1.1 对其进行了测试,生成的 pdf 应该符合您的规范。

<?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>

关于xslt - XSL-FO 根据页面位置不同的页眉/页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28366990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com