Search code examples
javaxmlxsltapache-fop

fop 2 + xsl = Image not found


When moving from one server to another, pictures no longer appear when generating pdf using fop 2 + xsl

Trying to understand someone else's code when generating pdf using fop 2 + xsl I get in the logs

[FOUserAgent] Image not found. URI: test/myimg2/logo.png (No context info available)

relative paths are specified in xsl, the full path to the image will be /myserv/mydir/test/myimg2/logo.png

I read that in version fop 2 you can set the base url using FopFactoryBuilder

FopFactoryBuilder builder = new FopFactoryBuilder(new File("/myserv/mydir/").toURI(), resolver);

However, in my code the following construct

FopConfParser parser = new FopConfParser(new File(fopBaseDir, "userconfig.xml"));
FopFactoryBuilder builder = parser.getFopFactoryBuilder();

fopBaseDir - fop library directory
fonts are specified in userconfig.xml

builder is already created using userconfig.xml

Can you please tell me how can I specify the base URL for images? Can this be done in userconfig.xml?

i don't use servlets, JSF

I debugged the code and saw that after creating the fop object, BaseUri leads to the userconfig.xml file

fop -> foUserAgent -> ResourceResolver -> BaseUri = file:/myserv/etc/tomcat/fop/userconfig.xml

Is this normal? Or is the BaseUri not the base url that is used to search for images?


Solution

  • One of the working options when using the configuration file is to specify the base url settings there

    <base>...</base>
    <font-base>...</font-base>