J. Lev
J. Lev

Reputation: 317

Why isn't my image displayed in XSL-FO?

In one of my project, I have to add image in a pdf with xslt and xml. However, my images isn't displaying at all.

Here's my xslt snippet

<fo:block text-align="left">
<fo:external-graphic src="url({$var})" content-height="6pt" content-width="6pt"/>
</fo:block>

(I've tried with and without the url part, but since it was already there I decided to show it in my question)

The variable var is declared in another files that is included.

<xsl:variable name="imgPath"></xsl:variable>
<xsl:variable name="var">
<xsl:value-of select="$imgPath"/>image.svg</xsl:variable>

The problem, I have is that even though I can see the right path of the image when I debug, the image is not displayed in the final result.

I don't think it is a problem with the location of the image since both the xsl and the images are at the same level (So image.svg is the correct path to access the image)

Upvotes: 3

Views: 2375

Answers (2)

J. Lev
J. Lev

Reputation: 317

So, the answer to my problem is that there were an accent in the name of my file which made my FOP unable to locate my files. Some time the most simple problems are the hardest to find.

Upvotes: 3

kjhughes
kjhughes

Reputation: 111541

SVG Embedded Graphics via XSL-FO

Apache FOP Embedded SVG Example

<?xml version="1.0" encoding="utf-8"?>
<!-- external-graphic-SVG-Diagram.fo
 - Copyright (c) 2016, HerongYang.com, All Rights Reserved.
-->
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <fo:layout-master-set>
  <fo:simple-page-master master-name="page" 
   margin="0.1in" page-height="4in" page-width="3in">
   <fo:region-body region-name="body" background-color="#eeffff"/>
  </fo:simple-page-master>
 </fo:layout-master-set>
 <fo:page-sequence master-reference="page">
  <fo:flow flow-name="body">
   <fo:block border-width="1px" border-style="solid">
    <fo:block-container width="1in" border-width="1px"
     border-style="solid">
     <fo:block>1 inch</fo:block>
    </fo:block-container>
    <fo:block-container width="72px" border-width="1px" 
     border-style="solid">
     <fo:block>72 px</fo:block>
    </fo:block-container>
    <fo:block-container width="120px" border-width="1px" 
     border-style="solid">
     <fo:block>120 px</fo:block>
    </fo:block-container>
    <fo:block border-width="1px" border-style="solid">
     SVG diagram of 288x288 px at a fixed resolution 144dpi:
    <fo:external-graphic src="sample.svg" width="2in" height="2in"
     content-width="scale-to-fit" content-height="scale-to-fit"/>
    </fo:block>
   </fo:block>
  </fo:flow>
 </fo:page-sequence>
</fo:root>

RenderX Embedded SVG Example

SVG directly embedded in XSL-FO:

<fo:block>
  Here is the image of a typical roadsign:
  <fo:instream-foreign-object content-height="1em">1 
    <svg:svg xmlns:svg="http://www.w3.org/2000/svg"2
             height="100" width="100" viewBox="-50 -50 100 100">
      <svg:circle r="50" style="fill:red; stroke:none"/>
      <svg:rect x="-40" y="-10" width="80" height="20"
                style="fill:white; stroke:none"/>             
    </svg:svg> 
  </fo:instream-foreign-object>
</fo:block>

Per the XEP User Guide, fo:instream-foreign-object can host SVG graphics.

Upvotes: 0

Related Questions