This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes FOP graphics problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "FOP graphics problem" Watch "FOP graphics problem" New topic

FOP graphics problem

Meghna Bhardwaj
Ranch Hand

Joined: Jun 08, 2007
Posts: 109
HI All,

I have been generating a PDF file using FOP, I want to put a gif onto the PDF. I can do this but only when the .gif file is on the C:/ drive of the machine. I want to use relative path, so that it works for all users.
When I put the logo.gif in my c:/ drive and have the below it works:

I am looking for the syntax to use for src='url("/logo.gif")'
Notice the single outer quotes and the double inner quotes - it only works this way for me. My <xsl:stylesheet version="1.0"> and also xml version is 1.0. The .gif file is actually in my Eclipse project workspace under WebContent, I am just not sure how I can refer to it using relative path. I have tried various different syntax combinations, but have been unsuccessful.

Any help, will be much much appreciated!

[ March 25, 2008: Message edited by: Meghna Bhardwaj ]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 39576
Here's something that has worked for me in the past:

[ March 25, 2008: Message edited by: Ulf Dittmer ]

Ping & DNS - updated with new look and Ping home screen widget
Meghna Bhardwaj
Ranch Hand

Joined: Jun 08, 2007
Posts: 109
Hi Ulf,

I really appreciate your response. I am trying this out right now. I am wondering where should I place the logo.gif in my Project workspace so that it finds it. My code is :

So should I place it in Eclipse under the folder

I am not too sure where the location ../../images/logo.gif will look for the image?

Thanks in advance.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18154

That's not a relative URI you have there. A relative URI would look like this:
And from what I can see, that would be relative to the base URI of your stylesheet. The XSL-FO recommendation doesn't say how relative URIs are handled, but it makes several references to the CSS specification, and that's what it says.
Meghna Bhardwaj
Ranch Hand

Joined: Jun 08, 2007
Posts: 109
Hi Paul,

I tried your idea of relative path so now my code is:

I have placed the logo.gif in the same folder in Eclipse as the .xsl sheet, however this does not work. I am getting the message below in Console:

[ERROR] 03/25/08 15:04:44 <>:
Image not available: url("logo.gif")

Any help will be great. Thanks.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18154

Okay. So the next question would be, what is the base URI of your stylesheet?
Meghna Bhardwaj
Ranch Hand

Joined: Jun 08, 2007
Posts: 109
Hi Paul,

Since I posted my previous message I have done the following-
I have rewritten my code to use UserAgent, we were using some old methods of FOP which are now deprecated. I am now back to getting the PDF generated correctly but still no image, after code restructuring. I am setting the base URL as follows:

FOUserAgent userAgent = fopFactory.newFOUserAgent();

I want the base URL to be where the .xsl file is currently located in the Eclipse project, not a hardcoded absolute path like the one in the example in the link provided below, which suggest:

If I did this only the machine running the application with this folder structure will be able to set the base URL all other machines will not. so I set the base URL as userAgent.setBaseURL("./");
However when trying to generate PDF I get in the console:

[ INFO] 03/26/08 10:10:31 >:
FOP base url is ./

[ERROR] 03/26/08 10:10:32 >:
Error with base URL "./"): no protocol: ./

I have placed the logo.gif in the same directory in Eclipse as the .xsl file, but it doesnt seem to like the base URL. My .xsl file has

<fo:external-graphic content-width="2.08in" content-height="0.72in" src="logo.gif" />

Also another question teh code for setbaseURL() is in a separate class which is located in a different directory than the .xsl. I placed the logo in this dir as well as where the .xsl is, still no luck!

Anybody know how to set baseURL to current location of .xsl.
I really appreciate any help.

I agree. Here's the link:
subject: FOP graphics problem
Similar Threads
Mulitple fo:page-sequence
fop: xml + xsl => pdf in xpdf ok, in acrobat not so. but via ps (xsl => ps => pdf)
XSL help required to display PDF
XSL-FO to PDF using fop
problem with fop