0

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.

Mathias Müller
  • 22,203
  • 13
  • 58
  • 75
Chai
  • 131
  • 2
  • 13
  • What XSLT and FO processors are you working with? Also, please include a larger sample of your code (if not the entire stylesheet) so that people can actually test this. – Mathias Müller Mar 20 '14 at 10:51
  • Hi Mathias, XSLT 1.0 and FO 1.0. But I cannot put entire stylesheet in here as it is too big and the other stuffs are not relevant to my problem. The pdf file I am generating has the figure. But if I reduce the height, width also gets reduced. I have tried giving height also to 100%. In that case, the bigger images get overlapped on the footer of the pdf file and gets cut. – Chai Mar 20 '14 at 14:45

1 Answers1

2

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>
Mathias Müller
  • 22,203
  • 13
  • 58
  • 75