Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » How integrate image in a JasperReport(Kepler Version)
How integrate image in a JasperReport [message #1444638] Tue, 14 October 2014 10:43 Go to next message
marco giudici is currently offline marco giudiciFriend
Messages: 204
Registered: February 2013
Location: Italy
Senior Member
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 #1445423 is a reply to message #1444638] Wed, 15 October 2014 12:19 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
I am not familiar with Jasper.

What is your setup? Where will be the images? I assume in the server...
Can your users upload some files or is is just a switch in order for you to select the appropriate image given a specific context (in this case I assume you know all the possible images when you deploy).

Here some links I found using google (I did not try it on my own, but the explanation seems good):
* Using Jasper Reports Part 5 (Adding dynamic path to images in jasper): how to add a parameter and use it as path for the image (step by step).
* Relative Path for subreport in JasperReport: more detailed explainations about how you can handle the problem of relative path (for images or subreport).

I think you have many possibilities. Please decribe precisely your setup, your use case and your problem.

16.10.2014: fixed the first URL

[Updated on: Thu, 16 October 2014 19:45]

Report message to a moderator

Re: How integrate image in a JasperReport [message #1445991 is a reply to message #1445423] Thu, 16 October 2014 07:33 Go to previous messageGo to next message
marco giudici is currently offline marco giudiciFriend
Messages: 204
Registered: February 2013
Location: Italy
Senior Member
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"
index.php/fa/19533/0/
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 Go to previous messageGo to next message
marco giudici is currently offline marco giudiciFriend
Messages: 204
Registered: February 2013
Location: Italy
Senior Member
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.
Re: How integrate image in a JasperReport [message #1446431 is a reply to message #1445991] Thu, 16 October 2014 21:01 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
marco giudici wrote on Thu, 16 October 2014 09:33
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.


I think if you want to access a ressource in an OSGi bundle (the scout server is one):
URL url = Activator.getDefault().getBundle().getResource("/resources/html/scout.gif");

URLConnection connection = url.openConnection();
InputStream imageStream = connection.getInputStream();

Where Activator is the Activator of the Bundle where the ressource is. Whis the rest of your code you should be able to load the BufferedImage.

I am still not sure to know what you try to do, but this is probabelly because I do not know JasperReport good enough.

By the way Kepler is an old version. From an open-source/community point of view the two supported versions at the moment are:
* Luna (Scout 4.0.1 at the moment, Scout 4.0.2 will be released in februray 2015).
* Mars (Mars milestones and corresponding versions for Eclipse Scout are listed on the wiki)

Re: How integrate image in a JasperReport [message #1446750 is a reply to message #1446431] Fri, 17 October 2014 08:52 Go to previous message
marco giudici is currently offline marco giudiciFriend
Messages: 204
Registered: February 2013
Location: Italy
Senior Member
Hi Jeremie,
your suggestion has solved my problem. Thank you very much Smile

[Updated on: Fri, 17 October 2014 08:52]

Report message to a moderator

Previous Topic:OSGi console with a compiled application (exe)
Next Topic:Waiting for a job in a unit test?
Goto Forum:
  


Current Time: Thu Apr 25 16:54:21 GMT 2024

Powered by FUDForum. Page generated in 0.03470 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top