XSL-FO - 如何为 fo:region-body 创建静态内容

XSL-FO - how to create static-content for fo:region-body

我必须为页眉、正文和页脚创建 fo:static-content。页眉和页脚已完成并且可以正常工作,但我的正文有问题。 fo:static-content 我输出的 PDF 第一页上没有任何内容。来自 fo:flow 的内容在下一页生成。我需要解释如何为 fo:region-body.

创建有效的 fo:static-content

下面是我的fo:layout-master-setfo:static-contentfo:flow

         <fo:layout-master-set>
            <!-- page master for the first page-->
            <fo:simple-page-master master-name="first-page" page-width="21cm" page-height="29.7cm">
                <fo:region-body region-name="first-page-content" margin-bottom="52mm" margin-right="10mm" margin-left="15mm" margin-top="87mm" />
                <fo:region-before region-name="first-page-header" />
                <fo:region-after region-name="first-page-footer" extent="52mm" />
            </fo:simple-page-master>
            <!--page master for all others pages-->
            <fo:simple-page-master master-name="other-page" page-width="21cm" page-height="29.7cm">
                <fo:region-body />
                <fo:region-before region-name="other-page-header" />
                <fo:region-after region-name="other-page-footer" />
            </fo:simple-page-master>
            <!--page master for last page-->
            <fo:simple-page-master master-name="last-page" page-width="21cm" page-height="29.7cm">
                <fo:region-body />
                <fo:region-before region-name="last-page-header" />
                <fo:region-after extent="52mm" region-name="last-page-footer" />
            </fo:simple-page-master>
            <fo:page-sequence-master master-name="pages">
                <fo:single-page-master-reference page-position="first" master-reference="first-page" />
                <fo:repeatable-page-master-alternatives>
                    <fo:conditional-page-master-reference page-position="rest" master-reference="other-page" />
                    <fo:conditional-page-master-reference page-position="last" master-reference="last-page" />
                </fo:repeatable-page-master-alternatives>
            </fo:page-sequence-master>
        </fo:layout-master-set>


        <fo:page-sequence master-reference="pages" font-family="Arial">
            <fo:static-content flow-name="first-page-content">
                <fo:block-container>
                    <fo:block>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis accusantium, culpa error totam odit blanditiis vitae facere, amet consequatur ratione laudantium velit quaerat delectus maiores ex deleniti soluta quas nostrum!</fo:block>
                </fo:block-container>
           </fo:static-content>
       </fo:page-sequence>


        <fo:flow flow-name="xsl-region-body" font-size="10">
            <fo:block-container>
                <fo:block>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur quod repellendus suscipit, quae fugit! Aliquid corrupti enim odio et rerum assumenda, veritatis, excepturi earum laborum fugit ea consequuntur explicabo eveniet!</fo:block>
            </fo:block-container>
                <fo:block id="end" />
        </fo:flow>

谢谢指教!

~拉德克

一个 fo:page-sequence 必须有一个 fo:flow。来自 https://www.w3.org/TR/xsl11/#fo_page-sequencefo:page-sequence 允许的内容是:

(title?,folio-prefix?,folio-suffix?,static-content*,flow+)

因此您可以拥有多个 fo:flow 但您必须至少拥有一个。

让您的内容发挥作用的一种方法是在您的第一个 fo:page-sequence 中将 fo:static-content 更改为 fo:flow。 (您现有的 fo:flow 也需要在 fo:page-sequence 内。)

另一种方法是将所有内容放在一起fo:page-sequence并在第一页的内容之后强制中断:

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
     xmlns:axf="http://www.antennahouse.com/names/XSL/Extensions"
     xml:lang="en">
  <fo:layout-master-set>
    <!-- page master for the first page-->
    <fo:simple-page-master master-name="first-page" page-width="21cm" page-height="29.7cm">
      <fo:region-body region-name="xsl-region-body" margin-bottom="52mm" margin-right="10mm" margin-left="15mm" margin-top="87mm" />
      <fo:region-before region-name="first-page-header" />
      <fo:region-after region-name="first-page-footer" extent="52mm" />
    </fo:simple-page-master>
    <!--page master for all others pages-->
    <fo:simple-page-master master-name="other-page" page-width="21cm" page-height="29.7cm">
      <fo:region-body />
      <fo:region-before region-name="other-page-header" />
      <fo:region-after region-name="other-page-footer" />
    </fo:simple-page-master>
    <!--page master for last page-->
    <fo:simple-page-master master-name="last-page" page-width="21cm" page-height="29.7cm">
      <fo:region-body />
      <fo:region-before region-name="last-page-header" />
      <fo:region-after extent="52mm" region-name="last-page-footer" />
    </fo:simple-page-master>
    <fo:page-sequence-master master-name="pages">
      <fo:repeatable-page-master-alternatives>
        <fo:conditional-page-master-reference page-position="first" master-reference="first-page" />
        <fo:conditional-page-master-reference page-position="rest" master-reference="other-page" />
        <fo:conditional-page-master-reference page-position="last" master-reference="last-page" />
      </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>
  </fo:layout-master-set>


  <fo:page-sequence master-reference="pages" font-family="Arial">
    <fo:flow flow-name="xsl-region-body">
      <fo:block-container break-after="page">
        <fo:block>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis accusantium, culpa error totam odit blanditiis vitae facere, amet consequatur ratione laudantium velit quaerat delectus maiores ex deleniti soluta quas nostrum!</fo:block>
      </fo:block-container>
      <fo:block-container>
        <fo:block>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur quod repellendus suscipit, quae fugit! Aliquid corrupti enim odio et rerum assumenda, veritatis, excepturi earum laborum fugit ea consequuntur explicabo eveniet!</fo:block>
      </fo:block-container>
      <fo:block id="end" />
    </fo:flow>
  </fo:page-sequence>
</fo:root>