Issue with textField position and isStretchWithOverflow baseline shifting - jasper-reports

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>

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.

How to create different page footer depending on a condition?

I have a requirement to show different footer depending on a condition.
My footer consists of many static labels and theoretically I can define a 'Print When Expression' for each of the labels. But it is inconvenient.
Q: Is it possible to select a different footer depending on a condition?
If not how else can I handle such situation without having to specify the condition in many places?
The xsd allows none or maximum one pageFooter tag with a maximum of one band.
but
This is a typical example where you can use the frame component, to group your data and decide if to display it.
Example displaying different frame with text fields depending on page number
<pageFooter>
<band height="60" splitType="Stretch">
<frame>
<reportElement x="0" y="0" width="540" height="60" uuid="d0198e94-8325-4909-9804-a8d393600ec5">
<printWhenExpression><![CDATA[$V{PAGE_NUMBER}%2!=0]]></printWhenExpression>
</reportElement>
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="379e2ac0-63ea-4493-bd38-1b7ca7b35d8c"/>
<textFieldExpression><![CDATA["Text Field 1"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="30" width="100" height="30" uuid="6598ba79-08b6-4997-953d-70b64f159e3b"/>
<textFieldExpression><![CDATA["Text Field 2"]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement x="0" y="0" width="540" height="60" uuid="d0198e94-8325-4909-9804-a8d393600ec5">
<printWhenExpression><![CDATA[$V{PAGE_NUMBER}%2==0]]></printWhenExpression>
</reportElement>
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="379e2ac0-63ea-4493-bd38-1b7ca7b35d8c"/>
<textFieldExpression><![CDATA["Text Field 3"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="30" width="100" height="30" uuid="6598ba79-08b6-4997-953d-70b64f159e3b"/>
<textFieldExpression><![CDATA["Text Field 4"]]></textFieldExpression>
</textField>
</frame>
</band>
</pageFooter>
add the different text of the different pageFooter's to different frame's, then set printWhenExpression on the frame component.

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

How do I hide a table column based on its content?

I have a report which contains a table. I would like to hide the columns of that table based on the result set of the query that backs the table. As an example, here is the XML for one of the columns:
<jr:column width="80">
<printWhenExpression>$F{Total1_header} != null</printWhenExpression>
<jr:columnHeader height="30" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="30" style="table_CH"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression>$F{Total1_header}</textFieldExpression>
</textField>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression>$F{Total1}</textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
For some reason, my report is complaining about the printWhenExpression. It claims that $F{Total1_header} does not exist. It does not complain however about the instance of $F{Total1_header} in the textFieldExpression.
I can't figure out why the field is avaiable for the textFieldExpression, but not the printWhenExpression.
Column has 'Column print when' property to hide/show the column by an expression.
Another way to delete columns is to modify the jasper design at runtime, then report compilation and then procees as usually. This method makes it possible to distribute unused width to remaining columns.
Roughly goes like this:
JasperDesign design = ...
JRDesignComponentElement tableElement = (JRDesignComponentElement) design.getTitle().getElementByKey(tableKey);
StandardTable tableComponent = (StandardTable) tableElement.getComponent();
col = tableComponent.getColumns().get(0);
tableComponent.removeColumn(col);
// Then compile the JasperDesign
JasperReport result=JasperCompileManager.compileReport(design);
For future readers
You should use this
<printWhenExpression><![CDATA[$F{Total1_header} != null]]></printWhenExpression>
Instead of
<printWhenExpression>$F{Total1_header} != null</printWhenExpression>

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

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.