Re: Size of imported SVG Graphics in PDF output

On 12.08.2008 12:07:45 david.vergnaud wrote:
> 
> Hi,
> 
> I'm pretty new to FOP, so there might be some aspects I have overlooked,
> still I have a question about setting the size of an SVG graphic I'm
> importing in my FOP file for it to be rendered into a PDF file. 
> I'm importing the base64-encoded SVG data in FOP using fo:external-graphic

If you use fo:instream-foreign-object instead, you don't have to encode
the SVG in base64 and it might also reduce memory consumption just a bit.
fo:instream-foreign-object has pretty much the same properties as
fo:external-graphic.

> It looks a bit like this:
> 
>   <fo:page-sequence master-reference="section1-page-sequence-master" format="1">
>     <fo:flow flow-name="xsl-region-body">
>       <fo:block widows="2" orphans="2" font-size="10pt" line-height="1.147" white-space-collapse="false">
>         <fo:block font-family="TimesNewRoman" font-size="12pt" language="EN-GB">
>           <fo:external-graphic  content-width="453.55pt" content-height="210.75pt" background-color="#DDDDDD" 
>               src="url(&quot;data:image/svg+xml;base64,PHN2ZyB4bWxucz0i....
> 	....dmc+Cg==&#xA;&quot;)"
>           />
>         </fo:block>
>       </fo:block>
>     </fo:flow>
>   </fo:page-sequence>
> 
> The original SVG file starts like this:
> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 21600 21600">
> 
> The SVG file is properly rendered, but FOP doesn't seem to really take
> the size into account. Using the background-color attribute, I've
> noticed that the "background area" behind the graphic is always square,
> and its size ("height" *and* "width") seems to be depending solely on
> the content-height -- i.e. changing the content-width doesn't lead to
> any change in the display size, while changing the content-height does. 

It could be that FOP doesn't behave 100% correctly in this case, as the
SVG itself doesn't really have an intrinsic size. I'll have to look into
this. But if you want to squeeze the image into the rectangle you
specify with content-width and content-height, you can set
scaling="non-uniform".

> I've tried changing the y-coordinate in the SVG's viewBox, surprisingly
> enough it didn't change the look of the graphic itself, it simply
> changed its y-position inside the square area FOP is putting it in --
> i.e. setting e.g. the viewBox's y-max to 15000 instead of 21600 leads
> to the graphic being displayed roughly in the vertical middle of the square
> area, while for 21600 it's located at the top. 

Well, in theory x and y on a a top-level SVG element shouldn't even have
an effect if you follow the SVG spec to the letter. x and y will only
help you a bit positioning the graphic inside the coordinate system. I
would discourage its use on a top-level SVG element.

> Does anyone have any idea how I can make the bounding area fit better
> to the actual shape of the graphic? I remember using the same syntax to
> include a PNG graphic, and didn't have the same problem. 

That's weird. SVG and PNG should behave the same, at least it does in my
tests. Are you using the latest FOP version (0.95)?

> Thx in advance!
> 
> David


HTH,
Jeremias Märki
_________________________________________________________
Jeremias Märki, Software-Development and Consulting
Contact Information: http://www.jeremias-maerki.ch/contact.html
Blog: http://www.jeremias-maerki.ch/blog/

Received on Tuesday, 12 August 2008 20:39:38 UTC