Marcin Erbel
Marcin Erbel

Reputation: 1643

net.sf.jasperreports.engine.JRException: Byte data not found

I'm trying to pass to template of a jasper reports string location. So I'm passing key of a parameter inside template and value. Everything was working when I had image inside my project, but I would like to have it on the other place. Is there any way to read parameters from, for instance properties file? I don't know why this sollution is not working:

My image:

<parameter name="imagesDir" class="java.lang.String" isForPrompting="false"/>

...

<image isLazy="true">
    <reportElement key="image-1" style="PHLabel" x="0" y="0" width="160" height="33"/>
    <imageExpression class="java.lang.String"><![CDATA["$P{imagesDir}"+"logo.bmp"]]></imageExpression>
</image>

error:

Error during exporting report statement_account_10 to PDF.
net.sf.jasperreports.engine.JRException: Byte data not found at : 
((java.lang.String)parameter_imagesDir.getValue())logo.bmp

Upvotes: 6

Views: 52646

Answers (3)

Pere
Pere

Reputation: 1075

I don't know if my case is exactly the same as @Cristian Arteaga's, but his solution inspired the one that worked for me.

In my case, this happened with a report that was created in Jaspersoft Studio 6.x, then opened back in iReport 4.5.1 (as I needed it to be compatible with that version of the library and, after many unsuccessful attempts, this was the only way for me to accomplish so), then being included as a subreport in another main report (when runing it as a stand-alone report it didn't happen).

All in all, it was as simply as deleting the image that was causing the problem, then importing it again. After prompting for the file and importing it, in properties, instead of showing only the name of the file, it would show also the full path. Compiled and tried the main report and no problems anymore.

Upvotes: 1

Cristian Arteaga
Cristian Arteaga

Reputation: 550

I had this issue and in my case the problem was the path of the image.

Initially I had something like:

<imageExpression><![CDATA["logo.bmp"]]></imageExpression>

Then I replaced it by:

<imageExpression><![CDATA["/home/reports/logo.bmp"]]></imageExpression>

Obviously it worked because I was using the absolute path (Which is not a good approach), Then I changed the static absolute path with a parameter for the images folder.

Upvotes: 6

Marcin Erbel
Marcin Erbel

Reputation: 1643

Ok i found it... Should be:

<image isLazy="true">
    <reportElement key="image-1" style="PHLabel" x="0" y="0" width="160" height="33"/>
    <imageExpression class="java.lang.String"><![CDATA[$P{imagesDir}+"logo.bmp"]]></imageExpression>
</image>

Upvotes: 8

Related Questions