aditya_gupta Posted June 27, 2007 Share Posted June 27, 2007 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 APIThe 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.ThanksAdityaPost edited by: aditya_gupta, at: 2007/06/27 09:31 Link to comment Share on other sites More sharing options...
wiciu Posted June 27, 2007 Share Posted June 27, 2007 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:36Post edited by: wiciu, at: 2007/06/27 13:37 Link to comment Share on other sites More sharing options...
aditya_gupta Posted June 29, 2007 Author Share Posted June 29, 2007 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/VoiceSession-7e037689d9c580f31f40d4a60a126ca0.jrxml[/file] Link to comment Share on other sites More sharing options...
wiciu Posted July 5, 2007 Share Posted July 5, 2007 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_this.zip[/file] Link to comment Share on other sites More sharing options...
aditya_gupta Posted July 5, 2007 Author Share Posted July 5, 2007 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 More sharing options...
wiciu Posted July 6, 2007 Share Posted July 6, 2007 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.jpgtemplate localization:C:/WebApp/web/template.jrxml Regards,Michael W. Post edited by: wiciu, at: 2007/07/06 09:52Post edited by: wiciu, at: 2007/07/06 09:55 Link to comment Share on other sites More sharing options...
aditya_gupta Posted July 6, 2007 Author Share Posted July 6, 2007 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 GPost edited by: aditya_gupta, at: 2007/07/06 12:46 Link to comment Share on other sites More sharing options...
wiciu Posted July 6, 2007 Share Posted July 6, 2007 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 More sharing options...
Teodor Danciu Posted July 11, 2007 Share Posted July 11, 2007 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 More sharing options...
demeritcowboy Posted August 24, 2007 Share Posted August 24, 2007 > 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 More sharing options...
arianhojat Posted September 25, 2007 Share Posted September 25, 2007 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 More sharing options...
demeritcowboy Posted September 28, 2007 Share Posted September 28, 2007 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. Link to comment Share on other sites More sharing options...
nykkit Posted July 14, 2009 Share Posted July 14, 2009 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 More sharing options...
jasperforum Posted January 31, 2011 Share Posted January 31, 2011 Hello teodard Please update on this regarding how to pass servlet context as a parameter Link to comment Share on other sites More sharing options...
jasperforum Posted January 31, 2011 Share Posted January 31, 2011 Please update on this ...regarding passing the servletcontext as a parameter Link to comment Share on other sites More sharing options...
satishmhiremath Posted September 19, 2017 Share Posted September 19, 2017 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 Hiremathsatishmhiremath@gmail.com Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now