XSL FO inline alignment

37,269

Solution 1

Elegance wasn't a stated requirement, but this should fit the bill:

<fo:block text-align-last="justify">
  LEFT TEXT
  <fo:leader leader-pattern="space" />
  RIGHT TEXT
</fo:block>

This works by justifying the last line of text in the block, so that the text begins at the left of the line and ends at the right. The leader, which is usually used on Table of Contents pages, stretches to fill the space between the left and right text. Normally it is used as <fo:leader leader-pattern="dots" />, which produces a stretch of periods, but in this case it merely provides a gulf of space.

Solution 2

This will do the trick:

<fo:table>
  <fo:table-column />
  <fo:table-column />

  <fo:table-body>
    <fo:table-row>
      <fo:table-cell>
        <fo:block>LEFT TEXT</fo:block>
      </fo:table-cell>
      <fo:table-cell>
        <fo:block text-align="right">RIGHT TEXT</fo:block>
      </fo:table-cell>
    </fo:table-row>
  </fo:table-body>
</fo:table>

Solution 3

<fo:inline-container vertical-align="top" inline-progression-dimension="49.9%">
    <fo:block>left content</fo:block>
</fo:inline-container>
<fo:inline-container vertical-align="top" inline-progression-dimension="49.9%">
    <fo:block>right-content</fo:block>
</fo:inline-container>

Verified working with FOP 2.0

Share:
37,269

Related videos on Youtube

Ikke
Author by

Ikke

At young age I already had much interest for computers. It all started with a book about QBasic which got me hooked to programming. Experimented and made lots of little programs for myself. Later on, I started doing more with web development, mainly PHP. Nowadays I'm a professional webdeveloper mainly developping in PHP. In my own time I also do little projects in Python.

Updated on July 09, 2022

Comments

  • Ikke
    Ikke almost 2 years

    I need to get text aligned right and left on the same line. This should be possible, but i can't seem to find a way. I'm using Apache FOP to convert xml to pdf.

    Can someone help me to get this right?

  • Ikke
    Ikke over 15 years
    Does not work. The two elements are on seperate lines, not on the same line.
  • Martijn Laarman
    Martijn Laarman over 15 years
    I've got everything set up at home as well now (needed to anyhow) could you be a bit more specific as to what you want and why fo:table will not work ?
  • Ikke
    Ikke about 15 years
    Too bad, Apache FOP doesn't support fo:float.
  • EthR
    EthR about 15 years
    alt soft, www.alt-soft.com , the package that I use just added support for it recently. i've not had the chance to try it out yet tho
  • Haroon
    Haroon over 11 years
    worked for me thank you (I added table and columns widths too)
  • MonoThreaded
    MonoThreaded over 11 years
    Works at table-row level as well. +1
  • Sauer
    Sauer about 7 years
    Wow... Finally a neat solution. I ALWAYS build complex one-row-tables for that. Thanks!