This question already has an answer here:
- External Styles in JasperReports 3 answers
I would like to found best solution for having same styles for dynamicReports and jasperReports. I started to use dynamicReports, however I found it hard to create unusual reports there. It was much easier to do that in iReport graphical builder. So now I have 50% reports which runs on Dynamic and 50% on Jasper.
Now I can't resolve style problem. I've created styles, fonts etc in Template class and used it for DynamicReports. After some magic like:
.setName("cellCenterStyle");
template().setColumnStyle(cellStyle)
I was able to use them for jasper, but this is not a full solution as some options still does not work, for example:
.setDetailEvenRowStyle(Template.evenIntensivStyle)
is working with dynamic, but jasper ignores is.
So, the question:
Could I use same styles for dynamic and jasper with clear structure and without needless "magic". I would prefer solution like *.css styles, but any help would be appreciated.
Use a parameter to reference the relative (or absolute) path to the styles file. The main report, for example, might contain:
This allows the report in iReport (or Jaspersoft Studio) to reference a relative path to the report styles, such as:
This path is relative to the report's
.jasper
file location.Then, in DynamicJasper, you can pass in a report parameter. The API call in DynamicJasper might not match the API call for the following JasperReports Library call, but it should be sufficiently similar to get the idea across:
Assuming that
/home/user/dev/reports/workspace
is the location for the.jasper
files as well as the workspace location for iReport/Jaspersoft Studio, then both DynamicJasper and the report development environment will find and use the same styles file.The full path to the styles file, in this example, would be:
Your directory paths, of course, will differ.
At this point, you can reference the same styles in both environments. See also: