2

I want my report to show images in rows depending on values of some other fields. E.g. like that:

column_1 | column_2
======================
  xyz    | <xyz.jpg>
  abc    | <abc.jpg>

column_1 holds text, column_2 displays image from a file text + ".jpg". I do this by setting Image Expression to: $F{COLUMN_1}+ ".jpg".

The problem is that it sometimes may (and in my case: will) happen that there won't exist an image file with the appropriate name. This generates "Error filling print... Byte data not found at : [some_image_path]".

Is there a way to handle such errors, say, by displaying some default image, when the specified file isn't there?

Alex K
  • 22,315
  • 19
  • 108
  • 236
Tosz
  • 308
  • 1
  • 5
  • 14
  • This post may help you: [How to show an image on jasper report?](http://stackoverflow.com/q/2746561/876298) – Alex K May 20 '14 at 15:17

4 Answers4

6

It turns out it is possible to decide what happens with the image on error using 'onErrorType'. Here is an example:

<image scaleImage="RealHeight" hAlign="Center" vAlign="Middle" onErrorType="Blank">

This sets image to blank when no image file is found, instead of finishing with error.

Tosz
  • 308
  • 1
  • 5
  • 14
0

view Designer-> Properties-> Parameters->click left->add-> Subreport parameter name image Value expresion Select whit double click IMAGEN(parameter)

yesy
  • 1
0

Tosz's solution works indeed, but is not very flexible : you only get a blank frame, or a default icon instead of the image.

To specify a custom behavior you can use the following expression :

$P{REPORT_FILE_RESOLVER}.resolveFile( $F{COLUMN_1}+ ".jpg" )

It returns null when the file is not found. For example, you can use it as image expression and specify a default image with a simple check :

$P{REPORT_FILE_RESOLVER}.resolveFile( $F{COLUMN_1}+ ".jpg" ) != null ? $F{COLUMN_1}+ ".jpg" : "default.jpg"
arfff
  • 31
  • 3
-1

Find the image data in the XML code probably it looks like this

<image>
     <reportElement x="0" y="0" width="164" height="126"/>
     <imageExpression class="java.lang.String">
         <![CDATA["coffee.jpg"]]>
     </imageExpression>
</image>

change coffee.jpg to its full path like this

<![CDATA["src\\formsAndReports\\coffee.jpg"]]>
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213