Loading ...
Sorry, an error occurred while loading the content.

Re: [XSL-FO] How can i include SVG document in a PDF file?

Expand Messages
  • Eric Smith
    ... Do something like this in your xml: and something like this in your xsl:
    Message 1 of 4 , Dec 4, 2001
    • 0 Attachment
      According to ysenez@... on Mon, Dec 03, 2001 at 10:55:56AM -0000:
      > I'm using FOP to generate some PDF files and now, i want to include a
      > SVG document.
      > I know i can generate a pdf from a svg file with command line:
      > java org.apache.batik.apps.rasterizer.Main -m application/pdf
      > document.svg
      > but that i want is include the document.svg while i generate a PDF
      > from a XML / XSL files (from a link to this document).
      >

      Do something like this in your xml:

      <graphic url="/home/eric/somesvg.svg">

      and something like this in your xsl:

      <xsl:template match="graphic">
      <fo:block>
      <!-- content-height="auto" content-width="auto" -->
      <fo:external-graphic src="{@url}"/>
      </fo:block>
      </xsl:if>
      </xsl:template>

      You can also use instream-foreign-object in your fo but then you
      need to explicitly declare the svg: namespace in each of your svg statements.

      It cost me a few hours to get the above to work with FOP - it came down to
      the namespace declaration headers and the image size -( and getting rid of my
      viewport declaration) - I had to scale all the dimensions in my svg file
      to get it all to work, even anyone wants a quick perl command to scale all the
      dimensions, font sizes etc - let me know.
      hopefully this will get you off to a quick start - (quicker than I had anyway
      the developers of fop are pretty cruel when it comes to debugging info):

      somesvg.svg:

      <?xml version="1" standalone="no"?>
      <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN"
      "http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd">

      <svg width="2000" height="1800" xml:space="preserve">
      <!-- four first rectangles -->
      <rect x="69" y="18" width="84" height="32"
      style="fill:rgb(197,207,169);stroke:rgb(0,0,128);stroke-width:0"/>
      <rect x="176" y="18" width="84" height="32"
      style="fill:rgb(197,207,169);stroke:rgb(0,0,128);stroke-width:0"/>
      <rect x="276" y="18" width="84" height="32"
      style="fill:rgb(197,207,169);stroke:rgb(0,0,128);stroke-width:0"/>
      <rect x="373" y="18" width="84" height="32"
      style="fill:rgb(197,207,169);stroke:rgb(0,0,128);stroke-width:0"/>
      <text x="294" y="40" style="fill:rgb(0,0,0);font-size:10;font-family:Arial">Bank</text>
      </svg>

      Also see the faq on the fop site for what svg features are
      supported.

      good luck.

      BTW my rendered fonts for the above example look awful - I tried a few things but gave up
      - anyone have any clues?
      --
      Eric Smith - currently using xalan and xsltproc - what a difference speed makes - and fop on linux
    Your message has been successfully submitted and would be delivered to recipients shortly.