This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

FOP graphics problem

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Thanks.
[ March 25, 2008: Message edited by: Meghna Bhardwaj ]
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's something that has worked for me in the past:

[ March 25, 2008: Message edited by: Ulf Dittmer ]
 
Meghna Bhardwaj
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
ProjectName/Webcontent/images/logo.gif

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

Thanks in advance.
 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not a relative URI you have there. A relative URI would look like this:

src='url("logo.gif")'

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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 <org.apache.fop.fo.flow.ExternalGraphic:bind():68>:
Image not available: url("logo.gif")

Any help will be great. Thanks.
 
Paul Clapham
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. So the next question would be, what is the base URI of your stylesheet?
 
Meghna Bhardwaj
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
userAgent.setBaseURL("./");

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:
userAgent.setBaseURL("file:///C:/Temp/");

http://xmlgraphics.apache.org/fop/stable/embedding.html#user-agent

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.

Regards.
 
What are your superhero powers? Go ahead and try them on this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!