Image relative path is not working when exporting

0

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

aditya_gupta's picture
Joined: Jun 25 2007 - 2:56pm
Last seen: 12 years 3 months ago

15 Answers:

0
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
wiciu's picture
12
Joined: Apr 11 2007 - 11:14pm
Last seen: 4 years 9 months ago
0
Hi,

It is still dont work . Do you have any other solution.

Attached is the jrxml file for your reference.

Aditya [file name=VoiceSession-7e037689d9c580f31f40d4a60a126ca0.jrxml size=34115]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/Voi...
aditya_gupta's picture
Joined: Jun 25 2007 - 2:56pm
Last seen: 12 years 3 months ago
0
Hello,
I attached 2 ziped files (with improved path within image). Look on image paths I proposed (and correct if it needs). In my templates this solution works.

Regards,
Michael W. [file name=try_this.zip size=6508]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/try...
wiciu's picture
12
Joined: Apr 11 2007 - 11:14pm
Last seen: 4 years 9 months ago
0
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
aditya_gupta's picture
Joined: Jun 25 2007 - 2:56pm
Last seen: 12 years 3 months ago
0
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
wiciu's picture
12
Joined: Apr 11 2007 - 11:14pm
Last seen: 4 years 9 months ago
0
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
aditya_gupta's picture
Joined: Jun 25 2007 - 2:56pm
Last seen: 12 years 3 months ago
0
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
wiciu's picture
12
Joined: Apr 11 2007 - 11:14pm
Last seen: 4 years 9 months ago
0
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/ServletConte...(java.lang.String)

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

I hope this helps.
Teodor
teodord's picture
4381
Joined: Jun 30 2006 - 9:00am
Last seen: 1 day 18 hours ago
0
> 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?
demeritcowboy's picture
Joined: Feb 5 2007 - 9:03am
Last seen: 12 years 8 months ago
0
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.
arianhojat's picture
Joined: Sep 18 2007 - 1:30am
Last seen: 12 years 1 month ago
0
No, and we ended up giving up on JasperServer for a couple reasons including this one.


I did get an answer somewhere else about needing to extend ViewReportAction, but it wasn't worth figuring out what they meant at that point.
demeritcowboy's picture
Joined: Feb 5 2007 - 9:03am
Last seen: 12 years 8 months ago
0

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
nykkit's picture
1
Joined: Jul 14 2009 - 2:58am
Last seen: 10 years 3 months ago
0
Hello teodard

Please update on this regarding how to pass servlet context as a parameter
jasperforum's picture
Joined: Jul 16 2010 - 5:48am
Last seen: 9 years 3 months ago
0

 

Please update on this ...regarding passing the servletcontext as a parameter

jasperforum's picture
Joined: Jul 16 2010 - 5:48am
Last seen: 9 years 3 months ago
0

Use the below expression in the image Expression of jasper report IDE on image properties of the jrxml and the relative image path 

 

getClass().getResource("META-INF/resources/webjars/EquityBankTools/themes/default/images/Logo.png").openStream()

 

Satish M Hiremath

satishmhiremath@gmail.com

satishmhiremath's picture
Joined: Sep 29 2016 - 7:06am
Last seen: 2 years 1 month ago
Feedback