28

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
  • 99,403
  • 23
  • 97
  • 120

6 Answers6

46

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.

Hilton Campbell
  • 6,065
  • 3
  • 47
  • 79
  • Wow... Finally a neat solution. I ALWAYS build complex one-row-tables for that. Thanks! – Sauer Feb 07 '17 at 17:04
12

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>
Hilton Campbell
  • 6,065
  • 3
  • 47
  • 79
5
<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

rstormer
  • 51
  • 1
  • 2
0

I create two blocks and on the second block I set this attribute:

margin-top="-4mm"

or what your font size and margin bottom are (just to look like they are on same line)

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
Morticia A. Addams
  • 363
  • 1
  • 7
  • 19
0

I dont't have the time right now to test this but check out http://www.w3.org/TR/xsl/#fo_float

float one right float the other left - i'd give it a shot if I was looking to do what you are describing

you could also use a table

unless by aligned right AND left you mean justified...

EthR
  • 1,924
  • 1
  • 12
  • 13
  • 1
    Too bad, Apache FOP doesn't support fo:float. – Ikke Feb 03 '09 at 07:48
  • 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 – EthR Feb 03 '09 at 20:56
-1

This is possible i'm not sure what the exact output is but have you tried:

<fo:block-container>
   <fo:block text-align="left">text</fo:block>
   <fo:block text-align="right">text</fo:block>
</fo:block-container >

I haven't done XSLFO in a while but i can certainly recommend Stylus Studio for XSL-FO development (and in general XML), The in-app debugging and previewing saved my ass on finishing deadlines on time. You can make Stylus work with the Apache FOP processor as well.

PS: I would have double checked if i had Apache FOP etcetera set up correctly back at home as well.

Martijn Laarman
  • 13,476
  • 44
  • 63
  • 1
    Does not work. The two elements are on seperate lines, not on the same line. – Ikke Dec 24 '08 at 17:07
  • 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 ? – Martijn Laarman Dec 24 '08 at 17:34