XSL FO inline alignment

Ikke picture Ikke · Dec 24, 2008 · Viewed 35.2k times · Source

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?

Answer

Hilton Campbell picture Hilton Campbell · Feb 26, 2009

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.