Hello Everyone,

I have been trying to do this for a while but I wasn't able to get it to work yet. I'm hoping someone can help me.

I am creating a XML with some information using DOM, so far so good.
I am creating a XML SVG of a graph using jfreechart + batik's SVGGraphics2D.
I want to import the svg as a element of my xml and send it all straight to the FOP renderer to output a PDF without saving anything to disk (only the final PDF).

After creating the chart I do the chart.draw() to the SVGGraphics2D then I import the element using document.importNome on the svgG2.getRoot() and appending the imported child to my original XML document (all goes well, the xmlns for the svg tag is removed on that import).
Now I pass that document to the be transformed to fo with XSLT. So I have a fo:instream-foreign-object tag in my XSL and inside of it I do a <xsl:copy-of select="/original/svg"/>. If the svg has no xmlns tag this operation works but when I try to FOP it to PDF I get a namespace problem. If I force the imported tag to have a xmlns tag (using importedElement.setAttribute("xmlns", "blablabla") then the copy-of returns empty.
I also tried to use xmlns:svg instead of xmlns and add prefix to the root svg tag or recursively to all the child tags and that didn't seem to work also.
It seems to work ok if I add manually the SVG to the XSL file (svg is rendered in the pdf) but it is not the way I need it to work.
I could use the svgG2.stream to a file and use a fo:external-graphic in the XSL (as I said I didn't want to have to write anything temporary to the disk), and it works that way BUT I have noticed that since the output svg file has no width and heigh tags the rendered image is cropped to a small square, then again if I manually insert the width and height attributes to the svg file all works nice.
I tried something like svgG2.getRoot().setAttribute("width", "123") before the stream to file but the resulting svg is empty.
Is there a easy or at least a working way to do what I need?

Thank you all in advance.

Reply via email to