Question

I need to display an svg image into my pdf file. Below is my xslt code:

<fo:block text-align="left"
          display-align="left"
          absolute-position="absolute"
          left="-1.5cm"
          top="-1cm">
  <fo:external-graphic content-width="scale-to-fit"
                         width="100%"
                         content-height="50%"
                         scaling="uniform">
    <xsl:attribute name="src">
         <xsl:value-of select="$src" />
    </xsl:attribute>
  </fo:external-graphic>
</fo:block>

Explaination: My xml has many images. The above code runs in a loop and displays the images one by one. But for some images with height more than the page height, the image is getting cut. So I tried giving height = 50%. But with this my image width is also reducing.

Basically what I want is the image should fit properly in the block. and bigger images should not be cut. They should fit in the block given. Please help.

Was it helpful?

Solution

But if I reduce the height, width also gets reduced.

This is presumably because you have specified scaling="uniform" on the graphic. This will always "preserve the aspect ratio" (see the relevant part of the specification here).

<fo:external-graphic content-width="scale-to-fit"
                     width="100%"
                     content-height="50%"
                     scaling="non-uniform">
   <!--...-->
</fo:external-graphic>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top