Jump to content

Problem with relative path to SVG image


The Dentist

Recommended Posts

As SVG seems to result in the best quality when exporting to PDF, this seems to be the way to go for our logo image. I've experimented with SVG the whole day now and found its support in the Jaspersoft Studio / Jasper Reports library quite cumbersome (although I think that it shouldn't have been treated differently than any other image format during report design). It becomes complicated especially when it's about pathing.

As we'll certainly work on the reports in a team, we'll surely use some version control system to share the reports and collaborate. Now, it's definately not said that any user involved in this will have his own copy of the report project checked out to the same path. This ways, we'll certainly need to use relative paths. Even more, the filestructure on our production system (with a java server hosting our reports) might differ from what we have on our developers systems as well. Of course, I found out that SVGs can be included using the following:

<image hAlign="Center" vAlign="Middle"><reportElement x="0" y="0" width="179" height="66"/><imageExpression class="net.sf.jasperreports.engine.JRRenderable"><![CDATA[net.sf.jasperreports.renderers.BatikRenderer.getInstanceFromLocation("./image/logo.svg")]]></imageExpression></image>[/code]

This is said to support relative paths, which I actually don't doubt. Still, I'd say this is broken. As it is, I wasn't able to run the report from inside Jaspersoft Studio as it told me that it couldn't find the image. The image is stored in a sub-directory of my report project, the path I am using seems to be correct. When adding a variable to the report with an expression like new File($P{RESSOURCE_DIR}).getAbsolutePath() (where RESSOURCE_DIR is a parameter yielding the relative path to the directory where the image is stored and whichs value is to be overwritten by our server application later), the path turned out to be relative from my eclipses install directory (my workspace is not there and users shouldn't be forced to do so IMO). I suppose that this is what happens when calling the BatikRenderer as well. At least, passing the variable to the renderer did not seem to be a problem, only the path is not resolved properly.

Does anybody have an idea how to specify a relative path using a placeholder parameter that can be overwritten by my server application?

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Can't you just upload your svg to your JRS and use URL instead of using a path?

net.sf.jasperreports.renderers.BatikRenderer.getInstance(new java.net.URL("http://server/path/to/logo.svg"))net.sf.jasperreports.renderers.BatikRenderer.getInstance(new java.net.URL("http://server/path/to/logo.svg"))

Link to comment
Share on other sites

Thank you for your quick reply. Maybe I got you wrong, but from what I see this would hardwire the location of the svg within the report. This may be a matter of taste, but I personally think that this is bad design as the server should decide on from where to load the ressources, not the report.

 

Also, this would mean that the report developers would need access to the image via http, which is not the case. Developers are meant to develop their reports solely within Jaspersoft Studio (the server is not meant to be used at this point), where the image can be found within the report project. An URL pointing to somewhere on our server wouldn't meet the requirements, that would make report development server dependent.

 

As of now, we have "solved" the problem by creating a subreport doing nothing else than embedding the svg (its xml source). In turn, this subreport can be included in our reports. This ways, we can have it stored in a subreport directory of our project during development and in a well-known subreport directory on the server(s) during tests and in production use. Ugly, but it suits our needs best.

Link to comment
Share on other sites

  • 1 month later...

I have little experience with image uploading, but I think you may take a look at this thread which talks about displaying image on jasper report by path. Hope it can offer some useful information. http://community.jaspersoft.com/sites/all/libraries/ckeditor/plugins/smiley/images/wink_smile.gif

 

http://stackoverflow.com/questions/2746561/how-to-show-an-image-on-jasper-report

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...