Passing parameter as String makes jasper report believe its a absolute file path, so you need another class. The most obvious would be java.awt.Image or java.io.InputStream.

I choose java.io.InputStream since this will require less code, so the first thing we need to do now is to decode the base64 image String.

There are several Base64 class that will do the job, I choose the org.apache.commons.codec.binary.Base64 since apache commons-codec.jar is already distributed with jasper report (dependencies). The decode will give us a byte array byte[], so now we need only to add a ByteArrayInputStream

Important notice: The smileyfaceimage needs to be without:data:image/png;base64,

EDIT: The problem of the OP (comments) was that with old jasper report lib (3.0) you need to specify the class in the imageExpression @see class="java.io.InputStream" the post has been update consequently since this works also in 6.0.

I have tried using table which did not succeed. I tough of using text field as html and passing image to it and set the alignment to left, but I found out that it is not possible to pass the image in text field. I started to solve the problem using jaspersoft Studio pro and with its html element.
However I could not figure out how to pass the image field from data base as the html source. The expression in the html element is:

If you use the html component to wrap text around image, not only do you have a problem of pulling the image from the database, the html component also creates an image of the html, hence the content may be resized/clipped depending on text length and settings on html (image) component.

I would suggest to use two textFields wrapped around the image (see jrxml) and then calculate where the text will break into next field, so you get first part of text in first textField and second part in second textField

Java code to calculate text's break point

This code demonstrate how you can use FontMetric to calculate where Jasper Report will break the text depending on the size of your textField (explanation of code is in comments). The code is not perfectly safe on NullPointer (null text) and on non over-flowing text, furthermore it can be optimized but I will leave this to OP

jrxml example using java code

In this short example, I use a parameter with some arbitrary sample text. The WrapImage class is in class path. I set a variable to the calculated break point. Then use substring on the text to get first part in first textfield, second in second textField To simplify example, I'm using an image from desktop, for how to pull image from database see: Using images stored in database

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="wrappingText" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryWithPageHeaderAndFooter="true" uuid="cd3e4316-a3c4-4847-a085-3bfa1d9425af">
<parameter name="longText" class="java.lang.String">
<defaultValueExpression><![CDATA["Whether you've come to ask questions, or to generously share what you know, remember that we’re all here to learn, together. Be welcoming and patient, especially with those who may not know everything you do. Oh, and bring your sense of humor. Just in case. That basically covers it. But these three guidelines may help: Rudeness and belittling language are not okay. Your tone should match the way you'd talk in person with someone you respect and whom you want to respect you. If you don't have time to say something politely, just leave it for someone who does. Be welcoming, be patient, and assume good intentions. Don't expect new users to know all the rules — they don't. And be patient while they learn. If you're here for help, make it as easy as possible for others to help you. Everyone here is volunteering, and no one responds well to demands for help. Don't be a jerk. These are just a few examples. If you see them, flag them. In summary, have fun, and be good to each other."]]></defaultValueExpression>
</parameter>
<variable name="breakPos" class="java.lang.Integer">
<initialValueExpression><![CDATA[WrapImage.getBreakPosition($P{longText}, 250, 100)]]></initialValueExpression>
</variable>
<title>
<band height="220" splitType="Stretch">
<image>
<reportElement x="10" y="20" width="80" height="80" uuid="6b4bb467-f7fd-4a15-994b-7c1a01b86428"/>
<imageExpression><![CDATA["C:\\Users\\pette\\Desktop\\queen_bee.jpg"]]></imageExpression>
</image>
<textField>
<reportElement x="100" y="0" width="250" height="100" uuid="f4507624-0410-4feb-9dc5-7d3342b882f0"/>
<textElement textAlignment="Justified" verticalAlignment="Bottom"/>
<textFieldExpression><![CDATA[$P{longText}.substring(0,$V{breakPos}.intValue())]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="100" width="350" height="120" uuid="8790bbdd-2066-4ceb-9fc9-dad6154df88c"/>
<textElement textAlignment="Justified"/>
<textFieldExpression><![CDATA[$P{longText}.substring($V{breakPos}.intValue()+1)]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>

It works fine, but if I change the location of MyProgram I'll have to also change the path in the expression.
I tried setting the expression to : ../images/logo.png but I got an error of "Byte data not found at : ../images/logo.png". Any help would be appreciated.

Answer:

There are several things that you could do.

One is to manually add a parameter called ProjectRoot in the report, use $P{ProjectRoot} + "images/logo.png" as image expression, and pass a value for ProjectRoot (taken from the environment) when you run the report.

Another approach is to leverage the fact that JasperReports also attempts to resolve image locations as classloader resources. Therefore if you add src/myprogram as a source folder so that images/logo.png gets to be part of your project's classpath at runtime, you'll be able to use "images/logo.png" as image expression.

A third solution is to register a FileRepositoryService extension in a JasperReportsContext instance that you would use for filling the report. The file repository service would be created with the current project root path, that you need to somehow determine from the environment. Having a repository service would also allow you to use "images/logo.png" as image expression. The code would look something like this:

But, in Jasper Studio, when I try to save my jrxml file, I have this error :

The method getBytes() is undefined for the type InputStream value = new java.io.ByteArrayInputStream(org.apache.commons.codec.binary.Base

I'm not very familiar with Jasper, and I tried few different ways to insert the image, but the closest thing I found is the link I gave above. I understood that I can't set class="java.io.InputStream" anymore in , is it the problem ?

Anyone would know what I missed here ?

Answer:

Ok, solution was actually very simple, thanks to @dada67.

First, I confused $P and $F, as I was using a Field, I had to use $F.

Then, decoding base64 was a mistake, I didn't need it. To sum it up, right code should be :

I have a unique case where I have a Logo on the PageHeader Band of Jasper and I was expecting that since it is on the Page header, it should be printed on every page but it is getting printed only on the first Page. Same Jrxml is generating logo on all pages if I run it from ireport designer, but on my Java application, it is generating the logo only on the first page. Is there anything I am doing wrong?

net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error
evaluating expression for source text:
net.sf.jasperreports.engine.util.JRImageLoader.loadAwtImageFromBytes($P{EnvParameter}.logo)
at
net.sf.jasperreports.engine.fill.JREvaluator.handleEvaluationException(JREvaluator.java:284)
at
net.sf.jasperreports.compilers.GroovyEvaluator.handleEvaluationException(GroovyEvaluator.java:98)
at
net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:316)
at
net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:672)
at
net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:640)
at
net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:1169)
at
net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:466)
at
net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:440)
at
net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:383)
at
net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:548)
at
net.sf.jasperreports.engine.fill.JRVerticalFiller.fillTitle(JRVerticalFiller.java:323)
at
net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:150)
at
net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:615)
at
net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:414)
at
net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:814)
at
net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:61)
at
net.sf.jasperreports.engine.fill.AbstractThreadSubreportRunner.run(AbstractThreadSubreportRunner.java:221)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745) Caused by:
groovy.lang.MissingMethodException: No signature of method: static
net.sf.jasperreports.engine.util.JRImageLoader.loadAwtImageFromBytes()
is applicable for argument types: ([B) values: [[-119, 80, 78, 71, 13,
10, 26, 10, 0, 0, 0, 13, 73, 72, 68, ...]] Possible solutions:
loadAwtImageFromBytes([B) at
groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1518)
at
groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1504)
at
org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:52)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
at
rptVTitolo_1558437271760_434544.evaluate(calculator_rptVTitolo_1558437271760_434544:203)
at
net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:302)
... 17 common frames omitted mag 21, 2019 1:17:36 PM
org.apache.catalina.core.StandardWrapperValve invoke

Answer:

What is wrong?

Looks like you are using wrong method for loading image.
The class JRImageLoader was changed during moving to 6.x version of engine and there is no static method loadAwtImageFromBytes(bytep[]) at this class at new versions of JasperReports (I believe that it was there at JR 5.5.0).

I used JRImageLoader.loadAwtImageFromBytes(byte[]) method for loading image from bytes array. As you can see we need to get instance of JRImageLoader first - I used default context using this code: JRImageLoader.getInstance(DefaultJasperReportsContext.getInstance()).

I am working on a spring-mvc project and I am using JasperReports for reporting purposes. I have a link that generates a report in pdf format. Link is working fine and report is generated, but the problem is pdf report is not displaying the image. Snippet from my jrxml file:

Can you tell me why image is not coming in the pdf, though the displays the image in JasperReport Designer with the same path. I have used JasperReports plugin in my eclipse to design reports. I deploy the project in jboss 6.4 through war file.
Thank you in advance.
-------UPDATE--------
I got the idea of checking the structure of project inside war from @KDavid-Valerio answer. It is different from the actual project structure. war structure looks something like this:

I want to display some tiff's which a stored in BLOB's in an oracle database. I just tried to convert them from tiff to jpg or png using im4java, but that didn't work. Maybe there is a possibility to display .tiff and other img data types in Jasper without converting them?! Or if not, does anybody have a detailed solution how to convert them? (which image class do I need to configure, how to implement in a scriptlet etc.)