Search code examples
javaxsl-fosaxonapache-fop

Position Graphic @ Bottom-Right in a Block using Apache FOP


Using Apache FOP I want to place an <fo:external-graphic> within an <fo:block> or a <fo:block-container> of a fixed size. The Graphic should be positioned in the bottom right-hand corner of the block. I just can't figure out how to specify the position. Any ideas anyone?

Now if I only had one Image it would be no problem to figure out where to position it, but I have multiple Images of slightly different sizes & want them (after - proportional - scaling) to be justified Bottom-Right.

In my desperation I tried <fo:external-graphic allowed-width-scale="150% 50% 25%"/> which according to w3c is a valid option, but Saxon threw a net.sf.saxon.trans.XPathException.

And now, by popular demand, some FO:

<fo:block-container position="absolute" top="42mm" left="192mm" width="70mm" background-color="red">
    <fo:block background-color="green">
            <fo:external-graphic border-style="none" content-height="13mm" src="wiki_96dpi_290x81_7673x2143my.jpg" background-color="blue"/>
    </fo:block>
</fo:block-container>

The result is the following:

The left-justified result

Now, how do I get the Image right-justified within the <fo:block-container> so the green is on the left? Like this:

Desired result, right-justified

So, after applying Tonys solution, the result looked like this:

<xsl:variable name="sign_height">13mm</xsl:variable><!-- Höhe des Unterschrifts -->
    :             :
    :             :
<fo:block-container position="absolute" top="42mm" left="192mm" width="70mm">
    <fo:block text-align="right" max-height="{$sign_height}" font-size="0" background-color="green">
        <fo:external-graphic content-height="{$sign_height}" src="wiki_96dpi_290x81_7673x2143my.jpg" border-style="none"/>
    </fo:block>
</fo:block-container>

Note how max-height="..." & font-size="0" on the <fo:block> also got rid of the (unwanted) Padding above & below the Image.

The final result


Solution

  • To just align the graphic to the right, add text-align="right" to the fo:block.


    To fit the fo:block to the graphic, also add max-height="13mm" font-size="0".