stretch a row to fit the data in jasper reports using iReport - jasper-reports

How do i stretch a text field to fit the data, If data exceeds the band height the text field doesn't stretch. I have added the text field tag in my jrxml...
The example:
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
style="dNew"
mode="Opaque"
x="200"
y="0"
width="200"
height="19"
key="value-2"
stretchType="RelativeToTallestObject"
positionType="Float"
isPrintInFirstWholeBand="true"
isPrintWhenDetailOverflows="true"/>
<box></box>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{DATA2}]]></textFieldExpression>
</textField>

Some bands do not stretch, but if you are talking about the detail band you can do something like this:
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="base" positionType="Float"
isPrintRepeatedValues="false" x="0" y="3"
width="380" height="26" isRemoveLineWhenBlank="true"/>
<textElement/>
<textFieldExpression class="java.lang.String">
<![CDATA[$P{information}]]></textFieldExpression>
</textField>
That is pasted from auto generated XML so there is a lot of extra stuff, but the isStretchWithOverflow="true" should work for you. This will make the field stretch down as the text fills it up.
I ususally use iReport to build my reports and it works quiet nicely. You can switch to an XML view in there too.

Related

How to combine two textFields into one box in RTF generated by Jasper reports?

I use Jasper Reports to generate RTF file.
In RTF each textField is represented as separate box:
I tried to use one frame for textFields:
<frame>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="220" y="45" width="406" height="75"/>
<textField>
<reportElement positionType="Float" x="0" y="0" width="406" height="60"/>
<textElement>
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA["Address:"]]></textFieldExpression>
</textField>
<textField hyperlinkType="Reference" hyperlinkTarget="Blank">
<reportElement x="0" y="57" width="200" height="15" key="textWithStyle" style="LinkField"/>
<textElement>
<font fontName="Arial" size="8" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA["here"]]></textFieldExpression>
<hyperlinkReferenceExpression><![CDATA["http:adress"]]></hyperlinkReferenceExpression>
</textField>
</frame>
But textFields also in the different boxes.
Is it possible to combine several textFields into one box like the following?
I know that I can add each text to one textField, but sometimes I need two separate textFields that I can manage inside one box.

Jasper breaking lines even with sufficient space to render just one line

I'm developing a Jasper report that has to be exported as a PDF from my web app.
The jasperreport.version is 5.5.1 and the web app is running on a Tomcat6 instance.
I've defined the following elements in my .jrxml:
<rectangle>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Transparent" x="415" y="21" width="140" height="28" uuid="52ceec4a-26bb-4efa-a4d2-af32c107d1d3"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</rectangle>
<textField isStretchWithOverflow="true">
<reportElement style="label" positionType="Float" x="415" y="20" width="140" height="14" uuid="f1394c5b-4921-4ccd-84ed-b1d3e44dc499"/>
<textElement markup="none">
<font size="9" isBold="true" isItalic="false"/>
</textElement>
<textFieldExpression><![CDATA[$R{nivel.gestao}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement style="campo" positionType="Float" stretchType="RelativeToTallestObject" x="415" y="34" width="140" height="15" uuid="3e1d2402-8b21-4f8e-9ee8-d57f1a870077"/>
<box bottomPadding="2"/>
<textElement verticalAlignment="Middle" markup="none">
<font size="9" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[$P{nivelGestao}]]></textFieldExpression>
</textField>
The problem is that Jasper renders the text with line breaks depending on which font family I use.
Using Helvetica:
Using Courier (the font I need):
How can I use the Courier font family and avoid the unintended line breaks?
Text with Courier font is wider. I suppose if you write some long text with Helvetica you see same stuff. Check out padding and margins.
And remove <box bottomPadding="2"/>.

Serial Number Repeating in Jasper Reports

I have used $V{REPORT_COUNT} TO DISPLAY SERIAL NUMBER OF THE RECORDS.For Each Record that is fetched from the database the serial number is displayed correctly.
However if one record that is printed has data more then it can accommodate on a page, it is displayed on the next page. I am fine with that too, however the serial number is again shown for that page Eg. 3 is the serial number and if 3 could not be accommodated on the same page the record is written in the next page and the order of serial number is 1 2 3 (First Page) 3 4 5 etc(second Page).
I want 3 to be displayed only once in the first page and not in the second page. I have uploaded a image of my layout and I do not want to show the circled part I am Using Ireport to design the page
Text Field Properties
This is for the REPORT_COUNT TEXTFIELD
<reportElement
mode="Opaque"
x="0"
y="0"
width="15"
height="30"
backcolor="#D3D3D3"
key="textField-9"
stretchType="RelativeToBandHeight"
positionType="Float"
isPrintRepeatedValues="false"
isRemoveLineWhenBlank="true"
isPrintWhenDetailOverflows="true"/>
<box topBorder="Thin" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Times New Roman" pdfFontName="Times-Bold" size="10" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
This properties for the right hand side text box which displays data:
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Opaque"
x="12"
y="0"
width="523"
height="13"
forecolor="#000000"
backcolor="#D3D3D3"
key="textField-2"
positionType="Float"
isRemoveLineWhenBlank="true"/>
<box topBorder="Thin" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>
<textElement verticalAlignment="Middle">
<font fontName="SansSerif" pdfFontName="Times-Bold" size="8" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[" "+$F{vesselName}+($F{type} == null ? "" : " ("+$F{type}+")")]]></textFieldExpression>
</textField>
Can you just tell us the properties you have set for the text fields?
I have just made a rough design of your scenario and I did not come across your issue. The row_count value is not getting repeated.
Refer below image.
Set a few properties to your variable:
<variable name="RECORD_COUNT" class="java.lang.String" incrementType="Column" calculation="Count">
<initialValueExpression><![CDATA[1]]></initialValueExpression>
</variable>

How to set x, y for a textElement in JasperReports depending on if above textElement is empty. And if non-empty show it down to the that textelement

Requirement:
If firstName and lastName is non empty. Show this at x=125, y=3 coordinates.
And show address down to it at x="125" y="26" coordinate. This is working fine.
Problem: If firstName/lastName are empty, Then we need to move the address element up and show it at x=125, y=3 coordinate itself.
This is where I am stuck. Please help me.
Please refer my jrxml file below:
<frame>
<reportElement key="frame-462" positionType="Float" mode="Transparent" x="0" y="50" width="390" height="70"/>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now">
<reportElement key="textField-844" positionType="Float" mode="Transparent" x="125" y="3" width="264" height="23"
isPrintWhenDetailOverflows="true" isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[(!$F{firstName}.isEmpty() && !$F{lastName}.isEmpty())]]></printWhenExpression>
</reportElement>
<textElement markup="styled">
<font fontName="Verdana" size="12"/>
</textElement>
<textFieldExpression>
<![CDATA[$F{firstName} + "<style pdfFontName='Helvetica-Oblique' size='11'>" + $F{lastName} + "</style>"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now">
<reportElement key="textField-843" mode="Transparent" positionType="Float" x="125" y="26" width="264"
height="42" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true"/>
<textElement markup="html">
<font fontName="Verdana" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
</textField>
<staticText>
<reportElement key="staticText-1249" positionType="Float" x="2" y="2" width="108" height="21"
isRemoveLineWhenBlank="true"/>
<textElement textAlignment="Left">
<font fontName="Verdana" size="12" isBold="false" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[ Address:]]></text>
</staticText>
</frame>
You have already set the isRemoveLineWhenBlank attribute, which will remove the empty space left by the textField. However, JasperReports cannot collapse vertical space unless that space is completely clear. If there is another element occupying the same line (in your case the staticText element), the empty space will be preserved. This is a bit like playing Tetris in reverse; You have to get rid of all of the blocks before the line will disappear.
Putting report elements into frames modifies this behaviour slightly. It is only the width of the parent frame that needs to be clear, instead of the width of the whole report. Therefore, by putting your name and address fields into a separate frame, the space occupied by the name field can collapse despite being aligned horizontally with the static text. I have modified your code snippet to demonstrate this:
<frame>
<reportElement key="frame-462" positionType="Float" mode="Transparent" x="0" y="50" width="390" height="70"/>
<frame>
<reportElement x="126" y="0" width="264" height="70"/>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now">
<reportElement key="textField-844" positionType="Float" mode="Transparent" x="0" y="3" width="264" height="23" isPrintWhenDetailOverflows="true" isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[(!$F{firstName}.isEmpty() && !$F{lastName}.isEmpty())]]></printWhenExpression>
</reportElement>
<textElement markup="styled">
<font fontName="Verdana" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{firstName} + "<style pdfFontName='Helvetica-Oblique' size='11'>" + $F{lastName} + "</style>"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now">
<reportElement key="textField-843" mode="Transparent" positionType="Float" x="0" y="26" width="264" height="42" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true"/>
<textElement markup="html">
<font fontName="Verdana" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
</textField>
</frame>
<staticText>
<reportElement key="staticText-1249" positionType="Float" x="2" y="2" width="108" height="21" isRemoveLineWhenBlank="true"/>
<textElement textAlignment="Left">
<font fontName="Verdana" size="12" isBold="false" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[ Address:]]></text>
</staticText>
</frame>

Issue with textField position and isStretchWithOverflow baseline shifting

I have a JasperReport with a textField element.
Simple XML:
<textField isStretchWithOverflow="true">
<reportElement uuid="2e3604dd-1f53-44d6-ab66-b3e41732955b" x="247" y="229" width="232" height="20"/>
<textElement>
<font fontName="CBSwiss721BT-Light"/>
</textElement>
<textFieldExpression>
<![CDATA[$F{meetingPurpose}]]>
</textFieldExpression>
</textField>
If the length of field's meetingPurpose value is less than the width of the textField, it prints beautifully, however if the length causes the text to wrap and stretch the textField, the text is baseline shifted down 1/2 X height.
I don't see anything like cell padding that I can access and I cannot figure this out. If it is a feature, is there an off switch?
I may be reading your problem all wrong but, to access Padding right click on the element pick padding and borders
it will alter your xml to look like this
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"/>
<textElement/>
<textFieldExpression><![CDATA[$F{SYSDATE}]]></textFieldExpression>
</textField>