Jump to content
We've recently updated our Privacy Statement, available here ×

Image relative path is not working when exporting


aditya_gupta

Recommended Posts

Hi,

I am using jasper reports and ireport to desing the report. The report is having a jpg image. I am giving the relative path to image in 'image expresion' field of ireport i.e "/client/resource/image/playUp.jpg"

The report is exported to differnet format(PDF, XLS, RTF) using web application i.e using jasper report API

The problem is that image is not getting rendered in PDF, XLS and RTF format. For HTML it is working fine.

The relative path starts from web application root.

How can i get images in pdf, xls, and rtf format providing the relative path .

Is there any way to embedd the image in pdf, xls, and rtf format.

Thanks

Aditya
Post edited by: aditya_gupta, at: 2007/06/27 09:31

Link to comment
Share on other sites

  • Replies 15
  • Created
  • Last Reply

Top Posters In This Topic

Hello,

use two backslashes instead one slash in paths to images.

 

Regards,

Michael W.

 

Post edited by: wiciu, at: 2007/06/27 13:35

 

Post edited by: wiciu, at: 2007/06/27 13:36

Post edited by: wiciu, at: 2007/06/27 13:37

Link to comment
Share on other sites

Hi,

 

Thanks for your reply. I have checked the both jrxml files,it is not working.

 

I have already tried with two backslashes but the image didnt appear.

 

Any other solution. I am totally in no where land.

 

Do you require any other file or code snippet? please let me know.

 

Aditya

Link to comment
Share on other sites

Hello,

I think that you have to check where your template and where your direcory with "playUp.jpg" image are situated. Maybe it is the problem. For example:

 

image localization: C:/resource/image/playUp.jpg (sorry, slash doesn't work on forum)

template localization: C:/template.jrxml

 

Open template.jrxml by iReport 2.0. In this case you should set path of image in template: "/resource/image/playUp.jpg" (remember: write two backslashes instead one of course). If path is OK then iReport automatically shows image content.

 

Example for web application which is deployed by NetBeans:

image localization:

C:/WebApp/web/resource/image/playUp.jpg

template localization:

C:/WebApp/web/template.jrxml

 

Regards,

Michael W.

 

Post edited by: wiciu, at: 2007/07/06 09:52

Post edited by: wiciu, at: 2007/07/06 09:55

Link to comment
Share on other sites

Hi,

 

First let you know that I am using jasper file in web appliaction and I have checked the path of both (image and jasper file). It is fine.

 

The image is coming when I am providing the relative path in ireport 1.3.0 but when I run the template in ireport as a pdf , the image is displayed in pdf because I have set the classpath of iReport to the image directory.

 

But when I am using this compiled template file(jasper file) in web application, the image is not there in pdf,rtf and xls format.

 

I am using the same method for template which have scriptlets jar file. i.e. Adding path of jar file to ireport classpath and my template file is another path.

So in web application i just add jar files as a library and use that jasper file. Its working fine there but for images it is not working.

 

For example, the path for template and image which is used in web application(using netbeans) is,

 

Image path:

D:/MyKnoahsARK 2.0/Report/web/config/knoahsoft/client/resource/image/playUp.jpg

 

 

Template jasper path:

D:/MyKnoahsARK 2.0/Report/web/config/knoahsoft/client/report/jasper/voicesession.jasper

 

I think the problem lies only with the path.

 

Do you know how to contact Tedord, forum administrator. He may solve this issue.

 

Thanks

 

Aditya G

Post edited by: aditya_gupta, at: 2007/07/06 12:46

Link to comment
Share on other sites

Hi,

I think similarly that the problem lies with the path. In web applications "web" is like a "root direcory" so maybe you should set path to image like this:

 

"/config/knoahsoft/client/resource/image/playUp.jpg"

 

Hm, I don't know how to contact Tedord.

 

Regards,

Michael W.

Post edited by: wiciu, at: 2007/07/06 13:13

Link to comment
Share on other sites

Hi,

 

I think you first need to understand how JasperReports exporters work with images, especially if they are "lazy-loaded" images (see the isLazy image flag).

I would only say that when you specify an image source using its relative URL within your current Web applications, you should expect it to work only when viewed in HTML format from within that Web application only.

 

Imagine you have a HTML file on your machine that loads an image from your local file system. And then you give that HTML to somebody else who does not have that image on their computers. How would you expect them to see the image, if the relative URL will not work on their machines?

A similar thing happens in this case you described here.

 

The PDF export process within your Web application, does not know anything about the Web context in which it is being executed. It cannot understand that those are relative URLs. Relative to what??...

If only you would have put complete URL locations for the images, something like http://www.mycompany.com/myapp/myfirstimage.jpg, the PDF export process would be able to load the images from their public location and embed them into PDF.

 

You could provide complete URL locations for the images by extracting them from the current application servlet context like this:

 

<imageExpression class="java.io.URL">$P{servletContext}.getResource("relative_image_location")

</imageExpression>

 

See this for more details:

http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#getResource(java.lang.String)

 

Of course, you would need to pass the servlet context as a parameter to the report.

 

I hope this helps.

Teodor

Link to comment
Share on other sites

  • 1 month later...

> Of course, you would need to pass

> the servlet context as a parameter

> to the report.

 

 

How do you pass it as a parameter when the report is running in JasperServer?

 

 

I tried setting up a parameter in the jrxml by importing javax.servlet.* and setting the parameter as type javax.servlet.ServletContext with value getServletConfig().getServletContext(), but that didn't seem to work. I tried a couple variations too. Am I in the right direction?

Link to comment
Share on other sites

  • 1 month later...

Did you end up figuring this out?

 

I have similar issue with paths to subreports not being found unless i do absolute url path, but this seems not good for long term.

 

I saw you can get servercontext/full path to item and pass as parameter to main jrxml file, but then the users who use just ireports instead of web app i think might have a problem as they are looking at jrxml files and not java app which would feed necessary subreport urls.

Link to comment
Share on other sites

  • 1 year later...

I have used iReport 3.5.2, but I still cannot pass relative path for showing image.

I have created an image field with expression class "java.io.File" and the image expression as "new java.io.File("logo.gif")".

The windows classpath and classpath in iReport are also set but it still cannot work.

Can anyone tell me how can I make it work?



Post Edited by nykkit at 07/14/2009 10:39
Link to comment
Share on other sites

  • 1 year later...
  • 6 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...