xslt-2.0xsl-foapache-fopxslt-3.0

How to Insert and adjust over lapping images While Rendering My PDF Using XSLT FOP


I want to display two images at the same position in my pdf where they will be overlapping to each other; or likely one image will be back ground of another image/logo so I tried below code:

<fo:table table-layout="fixed" width="100%">
  <fo:table-column column-width="proportional-column-width(4.5)"/>
  <fo:table-column column-width="proportional-column-width(1)"/>
   <fo:table-body>
    <fo:table-row>
      <fo:table-cell column-number="2">
        <fo:block-container background-image="file:///{$Logo}/Image2.png">
        <fo:block>
         <fo:external-graphic  src="file:///{$Logo}/Image1.png" content-height="16mm" content-width="45mm" scaling="non-uniform"/>
        </fo:block>
       </fo:block-container>
      </fo:table-cell>
     </fo:table-row>
    </fo:table-body>
 </fo:table>

Now that Image2 is coming as back ground for Image1 but I need to resize or fix the position for Image2 ; what all property I can use?

For example lets say

  1. Image2 should came in the middle/in the center as the Image1 back ground.
  2. Want to decrease the height and length of Image2. How i can do all these things?

Is this the correct approach I am using or should I used any other approach ?


Solution

  • You can position the background image using background-position (see https://www.w3.org/TR/xsl11/#background-position).

    There's a background-position sample from the XSL-FO Samples Collection (https://www.antennahouse.com/xsl-fo-sample) available at https://www.antennahouse.com/hubfs/xsl-fo-sample/structure/background-position-1.pdf, but be aware that XSL 1.1 only allows a length to be used with another length, a percentage to be used with a percentage, and a keyword to be used with a keyword.

    XSL 1.1 doesn't have a property for sizing the background image. FOP has extension properties for background image width and height (see https://xmlgraphics.apache.org/fop/2.8/extensions.html#backgroundimages), but I've never tried them.