1
votes

I'm getting closer now to Apache FOP and XSLT.

I wanted to do a simple thing: in output pdf that produce from my java project in eclipse, put on the first page an image and title.

For now, I can put only the title, but the image on the output pdf there isn't.

In my XSL file, I've put this "code" to obtain image, only in the first page

  <fo:block text-align="center" space-after="4cm">
                          <fo:external-graphic content-height="50%" scaling="uniform" width="50%" content-width="scale-down-to-fit" src="url('file:c:///UPLOAD/logo.png')"/>
                        </fo:block> 

and works. This is the way I've found on web about direct path for external resources. But in this way it's related to machine.

So, how can I have an image from the path "relative" of the project, I need that the pdf output are related to project not to filesystem (so in the JAR file when I deploy app)

Searching on the web, I found a lot of question about configuration FOP and so on..

There is a simple way If I want to use an image in my eclipse project directory (so, when the app deployed, use internal resources) in a XSLT document (like works with external file)?

I try this way

<fo:external-graphic content-height="50%" scaling="uniform" width="50%" content-width="scale-down-to-fit" src='url("///mtproject/WebContent/resources/default/img/logo.jpg")'/>

but in logs there is this error:

FOUserAgent - Image not found. URI: ///mtproject/WebContent/resources/default/img/logo.jpg. (No context info available)

How can I use a reference to a project resource?

Thanks in advance to all.

1
For one, the argument to the url () function is a string and should be quoted. What messages did you get in FOP log?Kevin Brown
I've update my post for a more clear question about. External resources on my filesystem works..but how can I use a resource of eclipse project?Domenico

1 Answers

1
votes

You have to define the working directory via the FOP's configuration.

Please have a look at the base element.