Search code examples
apache-fop

Apache FOP: How to set base URL for accessing external resource using relative path


In my .xsl file I am using external graphics like this
<fo:external-graphic width="90pt" height="29pt" src="url(xsl/logo.jpg)"/>

But image is not getting loaded in the generated PDF and I get this error in console.
[ERROR] Error while creating area : Error with image URL: xsl\logo.jpg (The system cannotfind the path specified) and no base URL is specified

How do I solve this issue? I guess setting the base URL will do. But how to set the base URL? Please help.


Solution

  • I got a solution from this link
    http://groups.yahoo.com/group/XSL-FO/message/6116

    set base dir using Java code

    ServletContext servletContext = getServletConfig().getServletContext();
    
    String appPath = servletContext.getRealPath(""); //root of web app
    org.apache.fop.configuration.Configuration.put("baseDir",appPath);
    

    This worked for me.
    Please post if you know any better solution.