aspose file tools*
The moose likes Other Open Source Projects and the fly likes Integrating Image in Jasper Reports using only Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Integrating Image in Jasper Reports using only Java" Watch "Integrating Image in Jasper Reports using only Java" New topic
Author

Integrating Image in Jasper Reports using only Java

Russell Howse
Greenhorn

Joined: Mar 09, 2010
Posts: 2
Hi All,

I'm fairly new to Jasper Reports, and have been trying to create my reports using only Java code, basing it off of the noXMLDesign App that comes with the samples. One thing that isn't included, is how to add images to the report. I've added the following (see code), but when the report tries to compile, I get the following error:

"illegal start of expression"
value = (java.lang.String)(![CDATA["D:My DocumentsNetBeansProjectsSTAT 0.1buildImageslogo.jpg"]]); //$JR_EXPR_ID=12$"



Now, my question is, how do I properly set the expression for the image in Java? The expression that I wrote is what the iReport builder gave me when I added an image to the report, I just added the escape characters for quotations.


Appreciate any help.

Regards,

Russell

Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Russel and welcome to Javaranch!

Strange that the escapes for the backslash aren't working. Can you quickly try forward slash to see if that gets removed by the parser as well?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Russell Howse
Greenhorn

Joined: Mar 09, 2010
Posts: 2
Thanks for the reply.

That's actually a bit of a mistake on my part. I've tried quite a few variations, and that error message didn't match the code I gave in my previous post. I added two escape backslashes in the directory to get two in the expression itself, as shown in the sample I ran through the designer. This is what it shows.

<imageExpression class="java.lang.String"><![CDATA["D:\\My Documents\\NetBeansProjects\\STAT 0.1\\build\\Images\\logo.jpg"]]></imageExpression>

My string value:

D:\My Documents\NetBeansProjects\STAT 0.1\StudentReport_1268229604078_194850.java:241: illegal start of expression
value = (java.lang.String)(![CDATA["D:\\My Documents\\NetBeansProjects\\STAT 0.1\\build\\Images\\logo.jpg"]]); //$JR_EXPR_ID=20$

With an arrow pointing to the first opening square bracket.

I've also tried
and because of Martin's post, tried this as well

However, I got the same error both times.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

You might have to do some experimentation at this stage just to see what the parser will accept. For example try giving it a (admittedly false) path with no slashes in it at all, is that a legal expression?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Integrating Image in Jasper Reports using only Java