I have an xml file which I need to visualize in a pdf file. I use xslt to do transformations and an svg image in the pdf.
The svg will finally draw some information and also display a tiff image, for which the path and the resolution is in the xml file. The problem is that the image can have different resolutions which I need to fit into the same boxed area. I do have the resolution and I have it working for two different resolutions, but a third resolution doesn't work. So what I need is a more generic solution.
At this moent I have the following code to draw the tiff image in the svg:
<!-- Draw the tiff image -->
<svg:g transform="translate({$svg_image_width_first},
{$svg_image_height_first})">
<svg:g transform="rotate({$tiff_rotation})">
<svg:g transform="scale({$scale_x} 1)">
<svg:image xlink:href="{$xml_bitmap_path}"
x="{$tiff_height_offset}"
y="{$tiff_width_offset}"
width="{$svg_image_height}"
height="{$svg_image_width}">
<svg:title>Front Image</svg:title>
</svg:image>
</svg:g>
</svg:g>
</svg:g>
I figured out that I need to do something with the scaleing so I leave the y scaling constant and alter the x scaling accordingly:
<xsl:variable name="scale_x" select="$horizontal_resolution div $vertical_resolution"/>
Due to the scaling the view of the svg changes and I need to alter the tiff_height_offset variable to be able to cope with the changes in the scale:
<!-- After rotation place of the image should be corrected-->
<xsl:variable name="tiff_height_offset">
<xsl:choose>
<xsl:when test="$tiff_rotation = '-90'">
<xsl:value-of select="0 - (($svg_image_height + ($svg_image_height * (1 div $scale_x )))div $scale_x)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
So these pieces of code seem to work for some resolutions but not for all. I hope someone can give me a solution or hint for how to make this generic for all kinds of resolutions.