如何使用 xsl-fo 创建包含两列的 PDF 页面

How can I create a PDF page with two columns with xsl-fo

我想从两个块创建一个 pdf 文件。第一个块应始终位于页面左侧,第二个块应始终位于页面右侧。 第二块始终朝向右侧非常重要。就算block里的一段文字会好几页,也应该只放在右边。

去看看。我用微软Word做了一个例子。请打开它来确切地知道我的意思:

Example made with ms-word

注意:这并不重要,应该使用什么(Table、块、容器等)。只要我能够拥有跨页面流动的列,这就是重要的。

fo:block-container 溢出时会发生什么有点模糊。有一个 overflow="repeat" 选项,但我不知道它的实施、使用或理解有多广泛。 (参见 https://www.w3.org/TR/xsl11/#overflow

我之前的回答确实限定了 fo:block-container 选项“分块不跨页”。您可以通过将每一面放在单独的 table 单元格中来处理占用超过一页的内容:

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:axf="http://www.antennahouse.com/names/XSL/Extensions"
    xml:lang="en"
    font-size="20pt">
    <fo:layout-master-set>
        <fo:simple-page-master master-name="spm" size="A6" margin="20mm">
            <fo:region-body/>
        </fo:simple-page-master>
    </fo:layout-master-set>
    <fo:page-sequence master-reference="spm">
      <fo:flow flow-name="xsl-region-body">
<fo:table>
  <fo:table-column column-width="50%" />
  <fo:table-column column-width="50%" />
  <fo:table-body>
    <fo:table-row>
      <fo:table-cell padding-right="6pt">
    <fo:block>:::::: First Block :::::::</fo:block>
      </fo:table-cell>
      <fo:table-cell padding-left="6pt">
    <fo:block>Lorem ipsum dolor sit amet consectetur adipiscing elit non quisque dictumst, ultrices curae cubilia justo at lectus fermentum gravida risus donec vulputate, posuere hac ornare convallis leo netus vestibulum vitae aliquam.</fo:block>
      </fo:table-cell>
    </fo:table-row>
  </fo:table-body>
</fo:table>
      </fo:flow>
    </fo:page-sequence>
</fo:root>

不是在 table 单元格上填充,另一种在两列之间设置间距的方法是在两列文本之间放置一个窄列。