Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image expression URL in Jasper Reports

Tags:

I would like to embed an image into my JasperReports jrxml file. I have this directory structure.

Tomcat Root  webapps   reports    -->images     --> company_logo.jpg    -->reports     -->sample.jasper    -->WEB-INF     -->classes 

And I tried doing this thinking that this is relative to my reports context root

<image>  <reportElement x="0" y="0" width="104" height="40"/>  <imageExpression class="java.lang.String">   <![CDATA["images/company_logo.jpg"]]>  </imageExpression> </image> 

..and this also

<image>  <reportElement x="0" y="0" width="104" height="40"/>  <imageExpression class="java.lang.String">   <![CDATA["/images/company_logo.jpg"]]>  </imageExpression> </image> 

but it always says there was an error loading bytes from location JRLoader.

I tried doing this and it works, but I am a bit confused why my first two attempt doesn't.

Is this really how you embed images in JasperReports? Do you need to supply the whole path? I am thinking that there should be a page relative something.

<image>  <reportElement x="0" y="0" width="104" height="40"/>  <imageExpression class="java.lang.String">   <![CDATA["http://localhost:8080/reports/images/company_logo.jpg"]]>  </imageExpression> </image> 

I am a bit puzzled about the correct way.

like image 941
Mark Estrada Avatar asked Sep 02 '10 02:09

Mark Estrada


People also ask

How do you hyperlink in Jasper report?

To make a textField a hyperlink to an external URL, you need to add the attribute hyperlinkType="Reference" to the element, and add a <hyperlinkReferenceExpression> tag within it. The reference expression is where you put the URL. The hyperlinkTarget attribute behaves in the same way as the target attribute in HTML.


1 Answers

<![CDATA["../images/company_logo.jpg"]]> should do the trick. The path is relative to your .jasper file.

like image 161
Giorgos Dimtsas Avatar answered Oct 06 '22 21:10

Giorgos Dimtsas