0

I am using Apache FOP to generate PDF's. My data is in a XML file and I use a XSL stylesheet to render it. I am having trouble using SVG in my stylesheet. I have create an SVG which is

<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.0" width="400" height="400" id="svg2">
<path d="M200,200  L390,200  A190,190 0 0,1 200,390  z"  fill="red" stroke="black" stroke-width="2"  fill-opacity="0.5" stroke-linejoin="round" />
<path d="M200,200  L200,390  A190,190 0 0,1 10,200  z"  fill="orange" stroke="black" stroke-width="2"  fill-opacity="0.5" stroke-linejoin="round" />
<path d="M200,200  L10,200  A190,190 0 0,1 200,10  z"  fill="yellow" stroke="black" stroke-width="2"  fill-opacity="0.5" stroke-linejoin="round" />
<path d="M200,200  L200,10  A190,190 0 0,1 390,200  z"  fill="green" stroke="black" stroke-width="2"  fill-opacity="0.5" stroke-linejoin="round" />
</svg>

But how do I put it in the stylesheet. I have tried putting it in an <fo:instream-foreign-object> like

<fo:instream-foreign-object  xmlns:svg="http://www.w3.org/2000/svg">
    <svg:svg width="400" height="400">
    <svg:path d="M200,200  L390,200  A190,190 0 0,1 200,390  z"  fill="red" stroke="black" stroke-width="2"  fill-opacity="0.5" stroke-linejoin="round" />
...
    </svg:svg>
</fo:instream-foreign-object>

But this doesn't work. Does anyone know what I'm doing wrong?

Pattle
  • 5,983
  • 8
  • 33
  • 56
  • `` should work, that's how they do it in one of their samples: http://xmlgraphics.apache.org/fop/dev/fo/embedding.fo (use view source). Please specify "doesn't work", that's too vague. – Tomalak Jul 12 '13 at 11:58

2 Answers2

0

He's my example of SVG inside FOP as a letter size background (with text 'background region'):

  <fo:block-container absolute-position="absolute"
        top="0in" left="0in" width="8.5in" height="11in"
        content-height="scale-to-fit"  content-width="scale-to-fit" 
        scaling="non-uniform"
        background-position="center"  background-repeat="no-repeat"
        background-image="url(your_xml_file.svg)">
    <fo:block>background region
    </fo:block>
  </fo:block-container>
Alvin K.
  • 4,329
  • 20
  • 25
0

its turns out I was doing it all wrong. The correct way to do it is rather than doing

<svg:path stroke="black" stroke-width="2"  fill-opacity="0.5" stroke-linejoin="round" />

You need to draw the path like this

<svg:path stroke="black" stroke-width="2"  fill-opacity="0.5" stroke-linejoin="round">
    <xsl:attribute name="fill">red</xsl:attribute>
    <xsl:attribute name="d">M200,200  L390,200  A190,190 0 0,1 200,390  z</xsl:attribute>
</svg:path>
Pattle
  • 5,983
  • 8
  • 33
  • 56