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

谁说我不能喝 提交于 2021-02-11 15:16:47

问题


I have to create fo:static-content for header, body and footer. Header and footer are done and it works but I have a problem with body. There is nothing on my output PDF's first page from fo:static-content. Content from fo:flow is generated on next page. I need explanation how to create working fo:static-content for fo:region-body.

Below is my fo:layout-master-set, fo:static-content and fo: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>

Thank you in advice!

~Radek


回答1:


An fo:page-sequence must have an fo:flow. The allowed content for fo:page-sequence from https://www.w3.org/TR/xsl11/#fo_page-sequence is:

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

so you can have more than one fo:flow but you have to have at least one.

One way to get your content to work is to change fo:static-content to fo:flow in your first fo:page-sequence. (Your existing fo:flow also needs to be inside an fo:page-sequence.)

Another way is to put everything in one fo:page-sequence and to force a break after the content on the first page:

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


来源:https://stackoverflow.com/questions/65019031/xsl-fo-how-to-create-static-content-for-foregion-body

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