How integrate image in a JasperReport [message #1444638] |
Tue, 14 October 2014 10:43 |
|
Hi all,
I followed the tutorial on how to create a JasperReport at this link
http://wiki.eclipse.org/Scout/Tutorial/3.9/JasperReports_Integration
I have the custom report based on my specific and works fine.
Now I have to integrate a logo in the report:
- for this reason I try to read this logo from file (.gif format)
- put into a stream
- send it as parameters to the report
I perform these actions in "ReportingService" class.
I'm quite confident that the second and third points works without problem, my big question is the first step because I have no idea exactly how to specify the file and its path in the correct way.
Can anyone suggest me the right path to follow?
I search something around and I find a method that use URL class, but I'm not sure.
Thanks in advance for any help and explanation
|
|
|
|
Re: How integrate image in a JasperReport [message #1445991 is a reply to message #1445423] |
Thu, 16 October 2014 07:33 |
|
Hi Jeremie,
I use eclipse Kepler with Scout and I use Jasper Studio 5.6.2 to edit my report.
The image is stored on the server side in the path "resources/images"
I override the method "createEDIOrderReport" in the class ReportingService, I personalize this method to set up all my parameters and the image is one of this.
I user the following code to load the image
// Load Image
BufferedImage bImageFromConvert;
try {
URL imageUrl = new URL("http://localhost:8080/Controller/images/logo.gif");
// Read the image ...
InputStream imageStream = imageUrl.openStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int n = 0;
while (-1 != (n = imageStream.read(buffer))) {
baos.write(buffer, 0, n);
}
baos.flush();
byte[] imageInByte = baos.toByteArray();
baos.close();
// convert byte array back to BufferedImage
InputStream in = new ByteArrayInputStream(imageInByte);
bImageFromConvert = ImageIO.read(in);
}
catch (MalformedURLException e) {
throw new ProcessingException("MalformedURLException occured during the creation of the report.", e);
}
catch (IOException e) {
throw new ProcessingException("IOException occured during the creation of the report.", e);
}
The problem occurs immediately when the execution try to open the stream "InputStream imageStream = imageUrl.openStream();" with the error message say that it's impossible find the resources.
This problem not occurs in the version with eclipse Juno with Scout and the same version of Jasper Studio; I use the same code with the same configuration.
Now I'll check links that you suggested in your post, just to understand if they can help me or not.
-
Attachment: Path.PNG
(Size: 9.21KB, Downloaded 4199 times)
|
|
|
Re: How integrate image in a JasperReport [message #1446210 is a reply to message #1445423] |
Thu, 16 October 2014 13:56 |
|
Hi Jeremie,
just to know, your first link is no longer available, instead the first one is available.
I try to solve my problem between the use of
HttpServletRequest servletRequest = null;
...
String reportFileNameSource = servletRequest.getSession().getServletContext().getRealPath("/images/logo.gif");
, but I don't understand how inizialize correctly the variable servletRequest in Scout.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03470 seconds