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.
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.
<![CDATA["../images/company_logo.jpg"]]>
should do the trick. The path is relative to your .jasper file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With