使用fop在偶数/奇数页上对齐图像

时间:2019-05-24 20:21:49

标签: xsl-fo apache-fop

我需要根据页码在页面正文中对齐图像:右对齐奇数页,左对齐偶数页。图片不会显示在页面的页眉/页脚中,而是显示在主要内容中。

搜索发现了一种使用可重复页面母版替代品和简单页面母版的偶数和奇数页的方法。我想我可以根据偶数/奇数页将参数传递给模板,并使用它来对齐图像。

这非常适合页眉和页脚。但是该解决方案在fo:page-sequence中使用了多个fo:flow块,而fop(2.3)并不喜欢这样;它报告

对于“ fo:page-sequence”,只能声明一个“ fo:flow”。

错误。

  <xsl:template match="/">
    <fo:root>
      <fo:layout-master-set>
        <fo:page-sequence-master master-name="recipes">          <fo:repeatable-page-master-alternatives>
            <fo:conditional-page-master-reference master-reference="recipes-odd" odd-or-even="odd"/>
            <fo:conditional-page-master-reference master-reference="recipes-even" odd-or-even="even"/>
          </fo:repeatable-page-master-alternatives>
        </fo:page-sequence-master>

        <fo:simple-page-master master-name="recipes-odd" page-height="{$height}" page-width="{$width}">
          <fo:region-body region-name="body-odd" margin="2cm"/>
          <fo:region-before region-name="before-odd" margin-top="0in" extent="3in" />
          <fo:region-after region-name="after-odd" extent=".5in" />
        </fo:simple-page-master>

        <fo:simple-page-master master-name="recipes-even" page-height="{$height}" page-width="{$width}">
          <fo:region-body region-name="body-even" margin="2cm"/>
          <fo:region-before region-name="before-even" margin-top="0in" extent="3in" />
          <fo:region-after region-name="after-even" extent=".5in" />
        </fo:simple-page-master>

      <xsl:apply-templates select="cookbook/*"/>
    </fo:root>
  </xsl:template>

  <xsl:template match="recipes">
    <fo:page-sequence master-reference="recipes">
      <fo:static-content flow-name="before-odd">
        <fo:block></fo:block>
      </fo:static-content>
      <fo:static-content flow-name="before-even">
        <fo:block></fo:block>
      </fo:static-content>
      <fo:static-content flow-name="after-odd">
        <fo:block></fo:block>
      </fo:static-content>
      <fo:static-content flow-name="after-even">
        <fo:block></fo:block>
      </fo:static-content>
      <fo:flow flow-name="body-odd">
        <fo:block>
          <xsl:apply-templates select="recipe">
            <xsl:sort select="name"/>
            <xsl:with-param name="side" select="right"/>
          </xsl:apply-templates>
        </fo:block>
      </fo:flow>
      <fo:flow flow-name="body-even">
        <fo:block>
          <xsl:apply-templates select="recipe">
            <xsl:sort select="name"/>
            <xsl:with-param name="side" select="left"/>
          </xsl:apply-templates>
        </fo:block>
      </fo:flow>
    </fo:page-sequence>
  </xsl:template>

是否有一种方法可以使fop处理多个流?如果不是,是否存在另一种基于页码控制图像对齐的方法?

0 个答案:

没有答案