Exclude of bands lead to excess whitespace - jasper-reports

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"/>

Related

Print application version for each report using JasperReports

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.

How to show checkbox (checked or unchecked) in report

I am using iReport 5.2.0. I'm trying show a parameter as checkbox: checked or unchechecked. How I can solve this task?
Answer by #Kudo
I'm using two images to display checkbox or uncheckbox. In each image, using Image Expression else if. ex: $P{param}.equals("TRUE") ? $P{imagecheck} : $P{imageuncheck}
I'm using a text field with this expression:
$F{b}!=null?"þ":"¨"
and set font: Wingdings.
The first symbol is a checked box, the second is an unchecked box.
So, if I want a check I just send a character from database in field b. If I want a blank box I leave b field null.
... and check this too:
http://jasperreports.sourceforge.net/sample.reference/fonts/
it provides information like "How to ship the required fonts with your report templates when deploying them in the target application, using font extensions."
You do not need to put images to create a checkbox. Just put a 11x11 rectangle. and add 2 pieces of 9x9 lines like "\" and "/" and laminate them(put on top of each other). Make the line at bottom Opaque and right click and send it backward. Make the line at top "not opaque". If not showing one of them true, just play with these back or front settings. Then center those laminated lines into your rectangle. After all you can set print when expression parts by code. thats all!
By the way you can reverse "\" line to "/", by line properties > direction > "bottom up" or "top down" settings. Have a nice day!
Another way is to use unicode ensure your jasper report has an encoding of:
...
<?xml version="1.0" encoding="UTF-8"?>
...
<field name="COLUMN_1" class ="java.lang.Boolean" />
...
<textFieldExpression class="java.lang.String">
<![CDATA[$F{COLUMN_1} ? "\u2713":"\u2717"]]>
</textFieldExpression>
...
Before:
After:

Jasper Reports - How to get JRXML components with mixed styles or dynamic widths on text boxes?

When buliding jasper reports JRXML files I want to be able to have a row of dynamically width'd text boxes of mixing styles. It does not seem like Jasper supports that so I'm stuck with this:
Notice how I used two static text boxes for this display with fixed widths. This is because I cannot mix the bold + normal font styles inside a component.
I would rather something like this:
Where the NOW() and $P{name} will automatically stretch out and look real nice.
Note: I cannot use the HTML component due to this issue http://community.jaspersoft.com/questions/540569/html-component-font and https://community.jaspersoft.com/jasperreports-library/issues/4411-0
Is there a way to code JRXML files with dynamically width'd Textboxes?
Actually, you can mix styles using markup in a single text box. Jasper supports (simple) HTML, RTF and a custom jasper-styling.
Check the "markup" property.
But I am not aware that you could insert artificial borders around the values when using a single textbox.

Disabling Crostab page break

Background:
I have a report with a large dataset on a crosstab element. The report will only cater to spreadsheet format so the width of the report will not matter.
I have tried setting the Ignore Pagination property to true. Split Type to prevent but some of the data still breaks and moves on the bottom of the sheet.
Any help would be greatly appreciated.
I found the solution to my problem. I was using iReport 3.7.4 and there was a bug in the UI. Apparently the crostabs property ignoreWidth="true" was showing as ticked in the UI but it was actually missing from the xml. You can locate this property in the crosstab tag as shown below:
<crosstab ignoreWidth="true">
...
</crosstab>

JasperReports XLS export pagination and other issues

I'm having trouble with JasperReports 4.0.2 XLS export. The file comes out but it seems to have certain issues each time, no matter which configuration I try:
Column headers will disappear unless I disable graphics e.g. vertical line separating the headers and the data.
I cannot remove repeating page and column headers and have all the data as a single details block. The page numbers cannot be removed also.
The same template is used for PDF export (which should have pages) and XLS export (which should be without pages). For achieving the desired XLS export I've tried configuring the export with JRXlsExporter parameters in the java code as well as changing properties in the default.jasperreports.properties file.
This far I haven't found any actual documentation on the topic. Few forums posts in the JasperReports site seem not to be working.
The Problem is solved.
Somehow JasperReports ignored the properties set in the java code during the export process with JRXlsExporter class and the properties file. However, the same delcarations did work then added directly to the JRXML file. The working code to remove repeating headers is below:
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.1" value="pageHeader"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.2" value="pageFooter"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.2" value="columnHeader"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/>
The titles did disappear due to separator line being drawn on top of the titles themself. PDF could handle this but XLS did not. By adding a few pixels of space in between the titles and the separator the problem did solve.