XSL:FO Keep the header only for first page

时光毁灭记忆、已成空白 提交于 2021-01-29 07:50:18

问题


I am having a problem to keep "region-before" only for first page. See my code:

    <fo:layout-master-set>
            <fo:simple-page-master master-name="first" margin-right="0.5cm" margin-left="0.5cm" margin-bottom="0.5cm" margin-top="0.75cm" page-width="21cm" page-height="29.7cm">

                <fo:region-body region-name="xsl-region-body" margin-top="{$extra-body-margin-top+15.6-$header-margin}cm" margin-bottom="3.5cm" />
                <fo:region-before region-name="xsl-region-before"  extent="17cm" overflow="hidden" />
                <fo:region-after region-name="xsl-region-after" extent="2.8cm" overflow="hidden" />
            </fo:simple-page-master>
            <fo:page-sequence-master master-name="psmA">
                <fo:repeatable-page-master-alternatives>
                    <fo:conditional-page-master-reference master-reference="first" page-position="any" />
                </fo:repeatable-page-master-alternatives>
            </fo:page-sequence-master>

    </fo:layout-master-set>

If I change the page-position="first" and my region-body exceeds the first page I got error. My idea is to keep the region-before only on the first page but the region-body and region-footer follow the next pages. Is any easy one to play with my code?


回答1:


  1. Set up a second fo:simple-page-master that does not have an fo:region-before.
  2. Add a second fo:conditional-page-master-reference so that the first page master is used on the first page only (using page-position="first") and the other page master is used for the rest (using page-position="any").

This works because the formatter uses the first alternative for which all its conditions are true (see https://www.w3.org/TR/xsl11/#fo_repeatable-page-master-alternatives). Which is also why you put the one with page-position="any" last, because that condition is always true.

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="first" margin-right="0.5cm" margin-left="0.5cm" margin-bottom="0.5cm" margin-top="0.75cm" page-width="21cm" page-height="29.7cm">

      <fo:region-body region-name="xsl-region-body" margin-top="1cm" margin-bottom="3.5cm" />
      <fo:region-before region-name="xsl-region-before"  extent="17cm" overflow="hidden" />
      <fo:region-after region-name="xsl-region-after" extent="2.8cm" overflow="hidden" />
    </fo:simple-page-master>
    <fo:simple-page-master master-name="rest" margin-right="0.5cm" margin-left="0.5cm" margin-bottom="0.5cm" margin-top="0.75cm" page-width="21cm" page-height="29.7cm">

      <fo:region-body region-name="xsl-region-body" margin-top="1cm" margin-bottom="3.5cm" />
    </fo:simple-page-master>
    <fo:page-sequence-master master-name="psmA">
      <fo:repeatable-page-master-alternatives>
        <fo:conditional-page-master-reference master-reference="first" page-position="first" />
        <fo:conditional-page-master-reference master-reference="rest" page-position="any" />
      </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>

  </fo:layout-master-set>

  <fo:page-sequence master-reference="psmA">
    <fo:static-content flow-name="xsl-region-before">
      <fo:block>before</fo:block>
    </fo:static-content>
    <fo:flow flow-name="xsl-region-body" font-size="12pt" line-height="11pt">
      <fo:block>content</fo:block>
      <fo:block break-before="page">more content</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>


来源:https://stackoverflow.com/questions/58341980/xslfo-keep-the-header-only-for-first-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!