How not apply page margins on the background image in JasperSoft Studio? - jasper-reports

I have TIBCO Jaspersoft® Studio 6.8.0.
My report has a background image. When I set page margins to i.e 20mm, it's applied to everything on the page(bands and background). I need to apply the margins to everything on the page except for the background so the background covers all the page including margins and the bands start printing after the page margins. Can this be accomplished?

No, you cannot have different margins on different bands.
Since you need the background image to be without margins you need to set the margins to 0 and then use as top margin the pageHeader band, bottom margin the pageFooter band*. The left and right margin are achieved by moving and sizing text elements.
The x position will be x=margin and width=pageWidth-2xmargin
Example
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Example" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isSummaryWithPageHeaderAndFooter="true" uuid="54602a93-638c-4747-847b-30d87b3dc24a">
<queryString>
<![CDATA[]]>
</queryString>
<background>
<band height="595" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</band>
</background>
<pageHeader>
<band height="40" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</band>
</pageHeader>
<detail>
<band height="31" splitType="Stretch">
<staticText>
<reportElement x="20" y="0" width="555" height="30" uuid="b619cb37-3c87-445d-8d23-58a4fe4cbbc8">
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement textAlignment="Justified" verticalAlignment="Middle"/>
<text><![CDATA[Example text in detail band position x=margin, width = page width - 2 x margin]]></text>
</staticText>
</band>
</detail>
<pageFooter>
<band height="20" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</band>
</pageFooter>
</jasperReport>
* If you are using summary band, make sure that isSummaryWithPageHeaderAndFooter="true", as in example to get the top and bottom margins also on the summary band.

Related

Jasper report: detail band with several images with different heights

I want to create a report for print several map legends. Right now I can generate the report with the title, and for each legend there is the name and the image below.
But all images are being resized to have the same height: the height of the container band (Detail 2 band).
I want that each image have its own height and not the height of the band.
How can I have images with different heights?
My report is:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="legend" pageWidth="555" pageHeight="802" columnWidth="185" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="6b65086b-74e0-4bec-834b-1b74d5ae2d31">
<property name="ireport.zoom" value="2.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<field name="name" class="java.lang.String"/>
<field name="icon" class="java.awt.Image"/>
<field name="level" class="java.lang.Integer"/>
<detail>
<band height="25" splitType="Prevent">
<printWhenExpression><![CDATA[!$F{name}.equals("")]]></printWhenExpression>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="6" width="555" height="13" uuid="804c03e8-4edc-4888-8dba-0c683717bfeb"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</band>
<band height="30" splitType="Stretch">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<printWhenExpression><![CDATA[$F{icon} != null]]></printWhenExpression>
<image scaleImage="RetainShape">
<reportElement positionType="Float" stretchType="ContainerHeight" x="0" y="0" width="555" height="30" uuid="067c1436-8c32-4bd6-9fd2-db394dc7366a"/>
<imageExpression><![CDATA[$F{icon}]]></imageExpression>
</image>
</band>
</detail>
</jasperReport>

How to split to new page when isIgnorePagination?

Using Jaspersoft studio 6.2.
A main report with detail and summary bands. A sub report in the summary band of the main report. The main report itself (when without the subreport) will split into two pages, so I checked isIgnorePagination and the main report (when without subreport) comes out as single page.
The subreport itself split to 9 pages by default, when I checked isIgnorePagination it comes out as one single page. Fine. When I put the subreport in the main report with all the settings above, it comes out as one single page. How can I make the main report in one page and subreport in another page (so two pages in total)?
EDIT
Tried break component, it works but there is still a problem. The page height of the main report has to be set to be big enough to include both main report and subreport, otherwise there will be more than 2 pages, but that will leave too much blank at the bottom of the main report. Below is an example to show what I meant.
main report:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-04-26T16:13:43 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="test11" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ce9d78e1-7194-4754-aaf9-93e871d2a5cf">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datamart"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<queryString>
<![CDATA[select 1 as a
union all select 2 as a]]>
</queryString>
<field name="a" class="java.lang.Integer"/>
<variable name="Total" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{a}]]></variableExpression>
</variable>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="50">
<staticText>
<reportElement x="54" y="0" width="100" height="30" uuid="e9116c0f-c827-4cb3-95d1-9155f4be7cb7"/>
<text><![CDATA[a]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="49" splitType="Stretch">
<textField>
<reportElement x="50" y="10" width="100" height="30" uuid="79fa53fa-48e2-43d0-96a4-0cda54e95c25"/>
<textFieldExpression><![CDATA[$F{a}]]></textFieldExpression>
</textField>
</band>
</detail>
<summary>
<band height="297" splitType="Stretch">
<textField>
<reportElement mode="Opaque" x="52" y="16" width="100" height="30" backcolor="#C4E5F6" uuid="2a393151-947e-4f1d-ab24-e456ce56bd19"/>
<textFieldExpression><![CDATA[$V{Total}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="62" y="97" width="200" height="200" uuid="b342cbae-597b-4ca5-b00d-3a4d047910f8"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["test12.jasper"]]></subreportExpression>
</subreport>
<break>
<reportElement x="0" y="60" width="619" height="1" uuid="ccc2155d-6a2e-4c23-a972-88bb871cb17d"/>
</break>
</band>
</summary>
</jasperReport>
sub report
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-04-26T16:14:10 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="test12" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3601f813-f6da-4105-a4d8-5c1ee1dd54d4">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datamart"/>
<queryString>
<![CDATA[select 10 as col
union all select 20 as col]]>
</queryString>
<field name="col" class="java.lang.Integer"/>
<variable name="total" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{col}]]></variableExpression>
</variable>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="73" y="0" width="100" height="30" uuid="5f2cfa26-c7ab-413e-94cf-80c1f1b288eb"/>
<text><![CDATA[col]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="73" y="90" width="100" height="30" uuid="3af983fb-00e2-4bb9-9e91-2d2214ca95d7"/>
<textFieldExpression><![CDATA[$F{col}]]></textFieldExpression>
</textField>
</band>
</detail>
<summary>
<band height="49" splitType="Stretch">
<textField>
<reportElement mode="Opaque" x="74" y="19" width="100" height="30" backcolor="#FFCC33" uuid="b333fb92-8aa8-4f00-9a1a-db24657d5521"/>
<textFieldExpression><![CDATA[$V{total}]]></textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>
There is a break in the main report, this works fine, 2 pages one for the main report and one for the sub report, but the main report leaves too much blank at the bottom, if I reduce the height of the main report (e.g. to 400 pixel), there will be more than 2 pages. Is it possible to get just 2 pages without too much blank?
To achieve different size for each page you need to use the attribute, isIgnorePagination="true" on the jasperReport tag.
When isIgnorePagination is true the break element is ignored by default you need to enabled it by setting this property net.sf.jasperreports.page.break.no.pagination to apply
ignore - page breaks are ignored in non paginated reports. (default) apply -
page breaks are honoured in non paginated reports.
<property name="net.sf.jasperreports.page.break.no.pagination" value="apply"/>
This will enable the break component and you can manuale break to new page using
<break>
<reportElement x="0" y="0" width="100" height="1" uuid="604c65b5-1127-4874-a63c-9b1a98dbf25c"/>
</break>

Jasper reports: positioning element on bottom of the page

I wonder if it's possible to position dynamically growing (table) element to the bottom of the page? My table element is on detail band, just above the page footer band.
Basically in my case the position of the topmost row of the table would be dynamically changing all the time based on the amount of rows in the table. But I'm not sure if creating this kind of presentation is even possible with Jasper where the table would be basically "growing" from bottom to top where the last row of the table would be basically fixed to the bottom of the page, just above page footer. There would be no problem if the position of the table's topmost row would be always fixed and table would "grow normally" from the fixed top position towards the bottom of the page...
I tried setting the table's position type property to Fix relative to bottom, but after that the whole table disappeared completely. This was the only thing I was able to think of so far to solve my issue.
Maybe the easiest way to achieve this is to put your table in a <groupFooter> with footerPosition="StackAtBottom"
The correct way to group depends on your datasource, but let assume you have just one table creating a dummy group.
Example of dummy group with table StackAtBottom of page
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Example2" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ca579c38-1e4f-4993-a020-efcea9d1096e">
<style name="table"><box><pen lineWidth="1.0" lineColor="#000000"/></box></style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF"><box><pen lineWidth="0.5" lineColor="#000000"/></box></style>
<subDataset name="Table" uuid="982be61b-ae46-4404-a9a0-30ba13e8c414">
<queryString language="xPath">
<![CDATA[/report/table/entry]]>
</queryString>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<field name="class" class="java.lang.String">
<fieldDescription><![CDATA[class]]></fieldDescription>
</field>
</subDataset>
<queryString language="xPath">
<![CDATA[/report]]>
</queryString>
<group name="dummy" footerPosition="StackAtBottom">
<groupFooter>
<band height="29">
<componentElement>
<reportElement key="table" style="table" x="0" y="0" width="360" height="20" uuid="53ea5a0e-1218-4150-ab5a-5f947e73b284"/>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Table" uuid="64092841-9993-4ccd-89b4-84a546c719cf">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("report/table/entry")]]></dataSourceExpression>
</datasetRun>
<jr:column width="90" uuid="4f5b1813-a9cc-4f83-9bdb-b0d8c4299133">
<jr:detailCell style="table_TD" height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="f1a97e19-e23d-40b6-ad95-10614f516db7"/>
<textFieldExpression><![CDATA[$F{class}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="98cfbe63-f865-419c-ad8f-d8af2ed706ba">
<jr:detailCell style="table_TD" height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="0480f047-02ba-4ec4-b12a-ef56a3cbfee9"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</groupFooter>
</group>
<detail>
<band height="17" splitType="Stretch"/>
</detail>
</jasperReport>
Result

Jasper Report - Detail won't print on first page

I have a report set up with a Title band and a Detail band containing a table. There is no spacing between these two bands. When I view/print the report, the Detail band begins printing at the top of page 2, and page 1 is left with a large blank space between the header and the footer.
How can I get the Detail band to print directly beneath the title on page 1?
Edit: Code below.
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Summary" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="24a40acb-a702-48a6-b655-04f85fdba2a9">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
...
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<staticText>
...
</staticText>
...
</band>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="753" splitType="Stretch">
<componentElement>
<reportElement uuid="3835c484-c5a2-4615-8018-b95d8d0b7f43" x="0" y="0" width="555" height="753" isPrintWhenDetailOverflows="true"/>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
...
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="29" splitType="Stretch">
<staticText>
...
</staticText>
...
</band>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
Most likely the detail band is so large that the report starts it on the second page to display as much of it as possible.
printWhenDetailOverflows should be the relevant parameter.
If your report is small enough (or the result is what you desired) you can set ignorePagination on the top element to true and get everything in one page.
Also, you have a pageHeight of 842, minus 40 margin makes 802 per page.
Your detail band is 753, the title is 79, so they don't fit together on one page.

Dynamically change width of element

I need to create table of contents in JasperReports.
I have already achieved this, but cant do anything with lines in TOC.
Currently they have a static width:
Chapter 1 ........ 2
Long Chapter Name ........ 3
End ........ 4
I want to stretch dotted lines to the width of the chapter name. Like here:
Chapter 1 ................. 2
Long Chapter Name ......... 3
End ....................... 4
How can I do this? Is there some 'padding' functionality in JR or should I create scriptlet for this task ? Thanks!
P.S. I'm using jasper reports 5.0.1
This wouldn't be a very neat way but I would draw many dots in your text box and hide the end using a frame to allow writing the number of the page.
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="table of content" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="df5894b6-0e62-4082-bdb8-3f0a1b26a2f4">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[SELECT
1 AS page,
'test' AS title
FROM
"account" account
Union
SELECT
4 AS page,
'chapter 2' AS title
FROM
"account" account
Union
SELECT
20 AS page,
'chapter 3: hello' AS title
FROM
"account" account]]>
</queryString>
<field name="page" class="java.lang.Integer"/>
<field name="title" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="20" splitType="Stretch">
<staticText>
<reportElement uuid="2e81fd32-3b8d-4b98-b96d-6409afb8d16f" x="0" y="0" width="555" height="20"/>
<textElement>
<font isBold="true" isStrikeThrough="false"/>
</textElement>
<text><![CDATA[Table of content]]></text>
</staticText>
</band>
</title>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="c8707508-946a-48ae-ae75-61810003e1db" x="0" y="0" width="555" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{title}+" .............................................................................................................................."]]></textFieldExpression>
</textField>
<frame>
<reportElement uuid="4040d203-6b49-4da2-8bcf-f3d6d48c7fd7" mode="Opaque" x="341" y="0" width="214" height="20"/>
</frame>
<textField>
<reportElement uuid="472f8f95-fdea-4cd9-b3a5-a1b9b66a8c44" mode="Opaque" x="321" y="0" width="20" height="20"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{page}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>