Search code examples
xmlxsltxslt-2.0xsl-fo

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


I want to create a pdf file from two blocks. The first block should always be oriented to the left side of the page and the second block should always be to the right side. It is very important that the second block is always oriented to the right side. Even if a text in the block will be several pages, it should be only on the right side.

To get a look. I made an example with microsoft Word. Please open it to know exactly, what i mean:

Example made with ms-word

Note: Its not important, what should be used (Table, blocks, container..etc). As long as I am able to have columns, which flow across pages, that is what is important.


Solution

  • What happens when an fo:block-container overflows is a bit murky. There is an overflow="repeat" option but I don't know how widely that is implemented, used, or understood. (See https://www.w3.org/TR/xsl11/#overflow)

    My previous answer did qualify the fo:block-container option with "chunks don't break across pages." You can handle the content taking more than a page by putting each side in a separate table cell:

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

    Instead of putting padding on the table cells, another way to get a gutter between the two columns would be to put a narrow column between the two columns of text.