JasperServer dynamic Band Height as Subreports have different heights - jasper-reports

I have a jrmxl report that uses different subreports with different heights, one is 421 and the other one is 600.
Is it possible for the report to dynamically set the band height on each page of the PDF that it generates?
<detail>
<band height="421">
<subreport>
<reportElement x="0" y="0" width="297" height="421" uuid="a23ff576-6d38-4582-a7ea-18e18926136c"/>
<subreportParameter name="NUMBER">
<subreportParameterExpression><![CDATA[$F{number}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$F{report}.trim()]]></subreportExpression>
</subreport>
</band>
</detail>

If your subreports need to produce pages of different sizes in the same resulting PDF document, then you need to use your subreport templates as parts in a part-based JRXML, AKA book report, as opposed to the usual band-based JRXML.
You can find a book report sample in our project distro under the /demo/samples/book folder.
Make sure you use JR Lib version 6.0.0 or newer.

Related

Jasper Reports subreport text alignment is wrong only when in main report

When I preview my jasper subreport, text is aligned to the right (what I want).
But when it is used in the main report, text is aligned to the left
On both reports, per element styling is used, set in Jasper Studio.
The jrxml per element looks like...
<textElement textAlignment="Right" markup="html">
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$F{col_1_initials}]]> </textFieldExpression>
The element including the subreport looks like
<band height="161" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<subreport isUsingCache="false" runToBottom="false">
<reportElement x="-20" y="0" width="595" height="161" uuid="4e6fb330-c43f-4d47-b7aa-6884dad63d14"/>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("weekPairs")]]></dataSourceExpression>
<subreportExpression><![CDATA["weeksubreport.jasper"]]></subreportExpression>
</subreport>
</band>
I'm not using report Style Templates because for a reason I can't diagnose, Jaspersoft Studio crashes instantly trying to assign a style template.
What about the main report ovverides the subreport text-aligment and what would I have to change in the source to fix this?
EDIT
In the report designer->properties of a jrxml file there is a checkbox for "Derive Attributes". I've tried that both on and off, but nothing changed.

I want "continue..." text when sub report will overflow to new page

I think, this should be a feature, when the subreport detail band overflow to the next page, that "...continued" or something should came, but I can't able to solve that issue and I have tried to find out, if there is any solution, but nothing works..
Can any one have a better idea, how to get the solution?
The "normal" way to do is:
In subreport put the text in the detail band (if it is not there already), if text without datasource (just pass a new net.sf.jasperreports.engine.JREmptyDataSource(1) to the subreport so that detail band is displayed one.
Having text in detail band allows us to use the pageFooter band, note
title band and summary band overflows on new page without the
pageFooter. You can also use the summary band but then you need to set attribute isSummaryWithPageHeaderAndFooter="true" on jasperReport tag.
In subreport add the a pageFooterBand with your text
es.
<pageFooter>
<band height="50">
<staticText>
<reportElement x="446" y="18" width="100" height="20" uuid="efa2e741-c546-4261-bdb7-a4b211212f17"/>
<text><![CDATA[...continued]]></text>
</staticText>
</band>
</pageFooter>
This will display the text "...continued" on every subreport page, since we like to avoid it on last page add empty lastPageFooter
<lastPageFooter>
<band height="50"/>
</lastPageFooter>

Jasper sub-reports of sub-reports - programmatically

There are many examples of running sub-reports in Jasper on the web, but nobody seems to have had the problem that I have, when running a sub-report that contains another sub-report.
We store our report definitions in a Relational Database, and generate and run the reports out of a java service. We only use the GUI to design and test each report, to start with.
The reports are compiled and filled at runtime, and I can cause a sub-report to run, by using the well documented feature of adding the compiled sub-report to the main report at fill time using the report expression to use a sub-report as a parameter.
That is all fine. However, how can I fill the first sub-report with the compile output of the next sub-report down the tree?
To explain a little further, in JasperStudio, I can do this in the main report:
<subreport>
<reportElement x="4" y="100" width="547" height="310" uuid="f9364882-a530-475d-97af-8d6d2d47ae57"/>
<subreportParameter name="INSP_ID">
<subreportParameterExpression><![CDATA[$F{jobid}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["InspectionFrogSubReport.jasper"]]></subreportExpression>
</subreport>
Then in the first sub report, to refer to the next one, I can do this:
<subreport>
<reportElement x="280" y="56" width="270" height="294" uuid="b4cbe376-1b54-471c-a6d4-0d45afeab2c8"/>
<subreportParameter name="FROG_ID">
<subreportParameterExpression><![CDATA[$F{frog_id}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["InspectionDamageSubReport.jasper"]]></subreportExpression>
</subreport>
So, when I preview the mian, it fills the first sub, and then the next sub, no problem.
However, to fill from Java method, I change the main sub-report expression to:
<subreport>
<reportElement x="4" y="100" width="547" height="310" uuid="f9364882-a530-475d-97af-8d6d2d47ae57"/>
<subreportParameter name="INSP_ID">
<subreportParameterExpression><![CDATA[$F{jobid}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["$P!{SUB1}"]]></subreportExpression>
</subreport>
Then in my code:
// Compile sub report
InputStream childStream = new ByteArrayInputStream(subReport.getChildXml().getBytes());
JasperReport compiledChild = JasperCompileManager.compileReport(childStream);
// Compile Main report
InputStream xmlStream = new ByteArrayInputStream(report.getXml().getBytes());
JasperReport compiledReport = JasperCompileManager.compileReport(xmlStream);
// Build report parameter map
Map<String, Object> params = new HashMap<>();
params.put("SUB1", compiledChild);
// Fill main report
JasperPrint jasperPrint = JasperFillManager.fillReport(compiledReport, params, conn);
so far, so good. However, how do I pass the sub-sub-report into the sub-report. I cannot use 'fillReport' as the sub report will have no master record to work on until the main report runs.
Pass subSubReport as a param to supReport.
in java code:
params.put("SUB_SUB_REPORT", compiledSubSubreport);
in main report template xml:
<subreportParameter name="SUB_SUB_REPORT">
<subreportParameterExpression><![CDATA[$P{SUB_SUB_REPORT}]]></subreportParameterExpression>
</subreportParameter>
this is what you want?

JasperReports: How to remove new page blank in subreport

I have create one report and put subreport into summary. I have problem to remove the new page blank in subreport because i have put clicks "run to bottom" in subreport's properties. After that, i run my report properly. The data appear correctly but problem comes when one new page blank appear after page. I don't know how to remove the blank page. Anyone know about this?
i know my mistakes is not put sub report by size band. Size band and sub ​​report must be the same size so that no blank page will come out.
I solve this adding the attribute isRemoveLineWhenBlank="true" for the reportElement tag:
<reportElement mode="Opaque" x="0" y="0" width="802" height="60" isRemoveLineWhenBlank="true" ...
And the band height, reportElement height and the subreport height must be equals:
<detail>
<band height="60" splitType="Stretch">
<subreport>
<reportElement mode="Opaque" x="0" y="0" width="802" height="60" ...

Make lines with iReport?

How can I do this with iReport (using iReport v4.0)?
Here is jrxml file
it depend on the size of Sub-report, check the sub-repot preview, if you want to increase the size of sub-rport in main report , for this you have to increase the size of sub-reportas where it is separately created.
You could try using background band for those lines.
Maybe inside your parent report
When you create a sub-report you can delete; Page Header, Column Header and Page Footer bands on your main report. After then, you can drag and drop sub-report icon on Summary part of your main report. You will probably use ColumnHeader and Detail bands on your Sub-Report. (It depends on your design. If you use subreports recursively, you can use again summary band.) Later,you will select Remove Report Margins on your subreport. To get expected result; your subreport icon Width on main report should equal your subreport page width.
Adding borders worked great for me. Expand your text element to cell size, right click -> Padding and Borders and add them all around. It's easier than having to handle draw lines. Less elements and faster editing.
You can add lines via the iReport Designer gui interface using the Palette (go to Window > Palette, then click Line, then drag it over to the Designer).
You can also add lines by modifying the jrxml code directly. I haven't found guidance in the documentation on this. But this answer to another question shows how to create a vertical line:
<line>
<reportElement x="0" y="0" width="1" height="30"/>
</line>
And it also shows how to create a horizontal line:
<line>
<reportElement x="0" y="0" width="30" height="1"/>
</line>
Also, the JRXML Sources and Jasper Files section of the documentation has some more involved code such as the following, which uses a direction parameter with value BottomUp (there are also references to TopDown in the community site or here):
<line direction="BottomUp">
<reportElement key="line" x="1" y="4" width="554" height="1"/>
</line>
And this, which uses positionType parameter of FixRelativeToBottom:
<line>
<reportElement positionType="FixRelativeToBottom" x="0" y="51" width="555"
height="1"/>
</line>