Print application version for each report using JasperReports - jasper-reports

We are using JasperReports 6.0.0 and have about 30 templates for different reports that have almost nothing in common. Today we have got a requirement to print application version at the bottom of each page for every report.
I could not find any good solution to do it without modifying every template file. Does JasperReport allows to specify general layout for all templates? Is there any solution to add label to each page without modifying existent templates?

Some approaches:
Modify all .jrxml files and add a footer to each one, manually.
Use XSLT to modify all the .jrxml templates and add a footer.
Use iText to modify the report output after generating the report PDF.
Use the JasperReports API to programmatically inject a footer band into the in-memory template prior to compilation and execution.
Use the JasperReports API to programmatically inject a footer band into each .jrxml file and save the file back to disk.
Create a master template and include a parameterized subreport.
The last approach would have a master template as follows:
-----------
| Title |
-----------
| Subreport |
-----------
| Footer |
-----------
Then, when running the report, pass in a parameter that indicates what subreport to include (i.e., one of thirty). In this fashion, the Title Band and Footer Band are shared by all thirty reports. It's more work, but ultimately the most flexible solution.
If the Title Band differs completely across all reports, parameterize it to use a subreport.
Here's a screenshot of a master report that includes a subreport, which is given as a parameter. In the screenshot, the Title Band doesn't include a subreport because each of the several reports looks identical (the human-readable report title is also a parameter). It should be easy to see that if the Title Band had to change its layout for each report, then using a subreport instead would facilitate such a solution:
The footer, though, as shown in the screenshot, is one possible answer to your question.
You may need to define a variable that allows for calculating the page numbers:
<variable name="V_CURRENT_PAGE_NUMBER" class="java.lang.Integer" resetType="Page">
<variableExpression><![CDATA[1]]></variableExpression>
<initialValueExpression><![CDATA[$V{PAGE_NUMBER}+1]]></initialValueExpression>
</variable>
And a corresponding text field that references the page number:
msg("Page {0} of {1}", $V{V_CURRENT_PAGE_NUMBER}, $V{PAGE_NUMBER})
Keeping in mind that JasperReports uses absolute paths, define a few parameters to avoid hard-coding the location of the subreports. For example:
$P{P_REPORT_SUBREPORTS_PATH} + $P{P_SUBREPORT_NAME} + ".jasper"
Here, P_REPORT_SUBREPORTS_PATH is defined in terms of a P_REPORT_BASE variable:
$P{P_REPORT_BASE} + "subreports/"
This allows the report IDE to use a different directory than that of the web server by providing a different value for P_REPORT_BASE, depending on context.
Finally, keep in mind that what might be seemingly different reports could be a parameterized report. JasperReports allows for custom styles, which makes possible to dynamically change the report appearance (e.g., text justification, fonts, emphasis, borders, and so forth). In the screenshot, the report title, for example, is changed with each of the several reports--but they all share the same Title Band because the report title is passed in as a String parameter.

Related

Printing the head line only on first page

I have jasper report which is created by many objects.
I want the header in one object. The object may come any where in the report.
How can i print header only on the first page of the object.
Can i use print when expression if page number equals 1.
is that page no means for whole pdf report or for only single jrxml object.
Thanks.
What does you mean anywhere in the report? If you want to print a title only once and in the first page, use the Title band in the jasper reports. No need of additional conditions required.

Exclude of bands lead to excess whitespace

Context
Setup: JasperReports server Product Version: 6.0.1 Build: 20141218_0238, CentOS server. I am using their bundled PostgreSQL + tomcat server setup.
In my report i have a table with text field and static field & and a chart in the summary band.
the static fields are in columnHeader band, and text fields are in the detail band.
I require the table because i want the users to be able to export CSV data.
However when the report is viewed as HTML, i want to exclude the two bands mentioned above (detail/columnHeader).
Problem
I am able to exclude the table so that it's not showed using the following:
net.sf.jasperreports.export.html.exclude.origin.band.1=detail
net.sf.jasperreports.export.html.exclude.origin.band.2=columnHeader
This does hide the two bands mentioned above, however now instead of the data - whitespace is shown, i would to know how i can remove it
The red text above was added by me, as you can see there are unwanted white-space between the title and the chart, that was where the columnHeader and detail band were at.
See the JRXML content.
Question
How can I remove the space?
It could be an issue with your styles or theme. I run the report in Jasper studio and there was no white space, but I created dummy styles (table_heading, table_data) and set the default theme for bar chart.
Here is my report
http://pastebin.com/fnAnvBR1
I'm using JasperStudio 5.6.2
Set the following property to true:
net.sf.jasperreports.export.html.remove.empty.space.between.rows
Earlier versions of JasperReports had a typo, for the property (emtpy instead of empty):
net.sf.jasperreports.export.html.remove.emtpy.space.between.rows
For example:
<property name="net.sf.jasperreports.export.html.remove.emtpy.space.between.rows" value="true"/>
<property name="net.sf.jasperreports.export.html.remove.empty.space.between.rows" value="true"/>

Linking subreports in iReport so they also work in Jasper server

Using iReport v4.0.1 with Jasperserver v4.1.0 I'm trying to find a syntax for linking subreports to the main report that lets me test it in iReport then deploy to the server through the repository browser.
The default syntax for sub-reports in iReport for the subreport expression is something like
$P{SUBREPORT_DIR} + "mySubReport.jasper"
When you deploy this from iReport it's smart enough to pick this up and suggest changing it to
"repo:mySubReport.jrxml"
and to then deploy all subreports to the Resources folder of the main report.
That's great, but unfortunately it then edits the file in iReport to save this change which means you can no longer run the report in iReport without manually re-editing all the sub-report expressions - this makes the process of testing and deploying to the server really painful, particularly when there are multiple sub-reports in a report.
I thought I could at least set the value of $P{SUBREPORT} to be "repo:" or "My\local\filepath" so that at least I'd only have one place to change it, but the compiler doesn't like that.
Is there an alternative structure or an expression that will resolve to repo:*.jrxml or My\local\filepath*.jasper correctly depending on where you're running the report from?
The best solution to this is to add an additional parameter like $P{IsOnServer}. Set the default value to true. For your subreport expression use this:
$P{IsOnServer} ? "repo:mySubReport.jrxml" : "/local/path/to/mySubReport.jasper"
When you run the report in iReport, you'll be prompted for the value of IsOnServer. Make it false; the subreport expression will resolve to your local file. On the server, don't define an input control. The users will never be prompted for that parameter (they won't even know it exists), and it will result to the desired 'repo' syntax.
An even better solution would of course be for iReport to handle this automatically... but for now you need to do something like this.

How to create jrxml for sub reporting

I want create a complex jrxml file to create PDF.
I want to put another jrxml in my jrxml file.
So.. my question is how to put one jrxml to another jrxml
My jrxml files are: salesreport.jrxml, financialreport.jrxml and report.jrxml
I want to put salesreport.jrxml and financialreport.jrxml to report.jrxml.
Usually you develop reports with iReport.
iReport has facilities for including subreports within reports (by dragging the subreport icon onto the master report page).
Note that JasperReports uses absolute paths for file references. I would recommend you set up parameters to your reports as follows:
$P{ROOT_DIR}
$P{SUBREPORT_DIR}
Give $P{SUBREPORT_DIR} a default value of $P{ROOT_DIR} + "subreports/".
At that point, you can pass the absolute path as $P{ROOT_DIR} into your report and then the subreports will be stored in a subdirectory called subreports, which is located in $P{ROOT_DIR}.
Or use the JasperCompileManager class from within the master jrxml file to dynamically compile it.
<subreportExpression><![CDATA[JasperCompileManager.compileReport($P{SUBREPORT_DIR}+"/myFile.jrxml")]]></subreportExpression>

Crystal Reports Check if export in formula

I want to add some text (from a formula) to my crystal report.
the thing is: I want this text only to be visible if I export the report to HTML for instance.
I don't want to see the text if I print the report.
Can it be done?
bye Juergen
Short answer: no. Crystal Reports, even v2008, doesn't have a mechanism to distinguish when it is being printed.
You could use a parameter field to set the field's visibility, but this will be a manual process.
You might be able to write a user-function library (UFL) to use the Windows API to determine the state of the document and return it to the report. The challenge would be to 1) find an API that can determine a document's print state 2) determine the report's 'handle'. I would go the c/c++ route for building such a UFL.
I don't think it's possible. The simplest way around your issue is to make 2 different versions of your CR report, 1 for HTML and 1 for printing.
A little redundant, yes, but it gets the job done.