JasperReports: Not support & sign when i use style - jasper-reports

Working in JasperReports:
<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction and instruction</style>
Not Working in JasperReports:
<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction & instruction</style>
Why this is happening?

I have used
&amp;
instead of "&" and it is working in jasper report.
<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction &amp; instruction</style>
//In text filed i have used style tag.
<textField isStretchWithOverflow="true" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="0"
y="0"
width="290"
height="15"
key="textField"
isRemoveLineWhenBlank="true"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" rightPadding="5" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Center" isStyledText="true">
<font size="9"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction &amp; instruction</style>]]></textFieldExpression>
</textField>

Try to use & instead of using & symbol.
The working sample:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ... whenNoDataType="AllSectionsNoDetail">
<style name="style1" forecolor="#FF0000" fontName="Serif" isBold="true" isItalic="true"/>
<title>
<band height="182" splitType="Stretch">
<staticText>
<reportElement style="style1" x="27" y="15" width="515" height="20"/>
<textElement/>
<text><![CDATA[Instruction and instruction]]></text>
</staticText>
<staticText>
<reportElement style="style1" x="27" y="46" width="515" height="20"/>
<textElement/>
<text><![CDATA[Instruction & instruction]]></text>
</staticText>
<staticText>
<reportElement x="27" y="78" width="515" height="20"/>
<textElement markup="styled"/>
<text><![CDATA[<style isBold='true'>Instruction and instruction</style>]]></text>
</staticText>
<staticText>
<reportElement x="27" y="108" width="515" height="20"/>
<textElement markup="styled"/>
<text><![CDATA[<style isBold='true'>Instruction & instruction</style>]]></text>
</staticText>
</band>
</title>
</jasperReport>
Note: The styled markup is using in this sample.
The result will be:
For more details you can view Creating Styled Text Using a Markup Language post and my answer on Style a text field in JasperReports question.

Related

Text Field dynamic height in JasperReports 6.12.2

I'm currently working in a API that will generate reports (with JasperReports 6.12.2), in this case I have to print a large String in a text field, the problem is that I can't give the appropiate behaviour to this element to adjust the height to the String size.
I've been searching before to ask, and all that I've found was about the property isStretchWithOverflow="true", but isn't working for me because in my version this is deprecated and replaced with textAdjust="StretchHeight" so basically all the results finish with the same, the text is cutted by the text field.
Note: Also I have to say that this necessity of dynamism is because i need to paginate the report.
Element Text Field JRXML code:
<textField textAdjust="StretchHeight">
<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="0" y="190" width="555" height="321" isPrintWhenDetailOverflows="true"/>
<textFieldExpression><![CDATA[$P{text}]]></textFieldExpression>
</textField>
Complete Band Detail JRXML code:
<detail>
<band height="802" splitType="Stretch">
<textField>
<reportElement x="0" y="40" width="140" height="20" uuid="8e0ef27f-45c4-45f5-8c36-93e126db95db"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.codigo}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="60" width="140" height="20" uuid="6cfe8e0b-0b7d-47f5-be4e-4c94d7f19fac"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.fecha}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="80" width="140" height="20" uuid="c8508fc6-3b17-4bcc-a207-2a9beff32263"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.enviado}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="100" width="140" height="20" uuid="5f7c732e-aeee-4896-bf11-dbd8f2c2b02f"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.asunto}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="120" width="140" height="20" uuid="71f51ac1-63c5-4abb-909a-3f31b14e0e80"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.canal}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="140" width="140" height="20" uuid="00e9ac8d-c331-429d-944a-240e6abf2107"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.nombre}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="160" width="140" height="20" uuid="4b22fdfb-36a3-41da-86d1-a527ca67667d"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.texto}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="150" y="40" width="405" height="20" uuid="bc346e06-c225-4451-bde7-67bde39d402e"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$P{codigo}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="150" y="60" width="405" height="20" uuid="1d0ac2a4-fcb9-4ad3-9d9d-db440ae5cfb3"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<textFieldExpression><![CDATA[new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").format( new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse($P{fAlta}))]]></textFieldExpression>
</textField>
<textField>
<reportElement x="150" y="80" width="405" height="20" uuid="d0189a13-4ded-45a1-82ad-5896a50f7fbf"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$P{mailPara}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="150" y="100" width="405" height="20" uuid="b0cfff7f-9230-4351-a59c-bf550fc4f0c2"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$P{asunto}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="150" y="140" width="405" height="20" uuid="15f48c57-404d-47e2-94a9-26da75054aa9"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$P{operador}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="150" y="120" width="405" height="20" uuid="0926440c-f596-47a4-b7b4-674faa82b407"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<text><![CDATA[Operador ATC]]></text>
</staticText>
<textField>
<reportElement x="0" y="20" width="140" height="20" uuid="664930ad-64a1-44fc-9cdb-4ef34eb7cffa"/>
<textElement>
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$R{respuesta.cuerpo.idPeticionATC}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="150" y="20" width="405" height="20" uuid="d9303c25-1ea8-45ca-b4b7-984a0b95d4ee"/>
<textElement>
<font fontName="SansSerif" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$P{idPeticionATC}]]></textFieldExpression>
</textField>
<textField textAdjust="StretchHeight">
<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="0" y="190" width="555" height="321" isPrintWhenDetailOverflows="true" uuid="0e59dd92-0a62-453a-9167-6a9d5b43ff54"/>
<textFieldExpression><![CDATA[$P{text}]]></textFieldExpression>
</textField>
</band>
After a while trying to solve this issue I've found the problem.
Recently Jasper Reports upgraded the version to v6.11 (Published: 2019-Dec-12), in this version Jaspersoft® Studio changed the property isstretchwithoverflow is replaced by textAdjust, so the problem was related with the version, and I realized that my Jasper reports library was in an older version v6.2, where the propertie textAdjust doesn't even exist.
So if anyone else is having this problem, please, check your library version, if it's under version 6.11 and your editor plugin is version 6.11 or higher, you will not be able to overflow texts and paginate properly.
The property isStretchWithOverflow was replaced in the JasperReports Library 6.10.0 by the textAdjust property. So to achieve the dynamic stretching effect, you need to set textAdjust="StretchHeight".
If you set your compatibility settings in Jaspersoft Studio ("Window > Preferences > Jaspersoft Studio > Compatibility") accordingly, it will automatically change the property to the compatible version, i.e. textAdjust="StretchHeight" will automatically be exchanged for isStretchWithOverflow="true" when you select a version <= JasperReports 6.5.1.

Colour issue in generated xls file with JasperReports

I am using Spring and iReport to generate jasper reports in excel format. All is working fine but I am having a single issue that the background colour of my reports in iReport is grey, but I am getting purplish hue in my generated Excel file.
I am setting Create Custom Palette to true, still it is not having any effect.
My Jrxml:
<?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="Charges Applicable" pageWidth="792" pageHeight="612" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="752" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" whenResourceMissingType="Empty" >
<property name="net.sf.jasperreports.export.xls.white.page.background" value="false"/>
<subDataset name="Table Dataset 1" >
<parameter name="ContractId" class="java.lang.String"/>
<parameter name="VersionNo" class="java.lang.String"/>
<queryString>
<![CDATA[SELECT S.TERM_COMMENTS FROM FCM_TX_TERMINATION_CHARGE_T S
WHERE S.CONTRACT_ID=$P{ContractId} AND S.VERSION_NO=$P{VersionNo}]]>
</queryString>
<field name="TERM_COMMENTS" class="java.lang.String"/>
</subDataset>
<parameter name="ContractId" class="java.lang.String"/>
<parameter name="VersionNo" class="java.lang.String"/>
<queryString>
<![CDATA[SELECT F.OFFSET_ABLE_AGAINST_SLA_FLAG SLA_PENALTY_APPLICABLE
FROM FCM_TX_BASIC_CONTRACT_DTLS_T F
WHERE F.CONTRACT_ID=$P{ContractId} AND F.VERSION_NO=$P{VersionNo}]]>
</queryString>
<field name="SLA_PENALTY_APPLICABLE" class="java.lang.String"/>
<summary>
<band height="120" splitType="Stretch">
<crosstab>
<reportElement x="0" y="0" width="352" height="30" />
<rowGroup name="SLA_PENALTY_APPLICABLE" width="200">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{SLA_PENALTY_APPLICABLE}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents backcolor="#F0F8FF" mode="Opaque">
<textField>
<reportElement positionType="Float" stretchType="RelativeToBandHeight" mode="Opaque" x="0" y="0" width="200" height="30" backcolor="#C9D9E7" />
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Arial" size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Is SLA Penalty Applicable"]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents/>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="SLA_PENALTY_APPLICABLE1" height="0">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{SLA_PENALTY_APPLICABLE}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents backcolor="#F0F8FF" mode="Opaque">
<textField>
<reportElement x="0" y="0" width="0" height="0" />
<textFieldExpression><![CDATA[$V{SLA_PENALTY_APPLICABLE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents/>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="SLA_PENALTY_APPLICABLEMeasure" class="java.lang.String">
<measureExpression><![CDATA[$F{SLA_PENALTY_APPLICABLE}]]></measureExpression>
</measure>
<crosstabCell width="100" height="30">
<cellContents>
<textField isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="30" />
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA[( $V{SLA_PENALTY_APPLICABLEMeasure}=="Y" ? "YES" : "NO" )]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell height="25" rowTotalGroup="SLA_PENALTY_APPLICABLE">
<cellContents backcolor="#BFE1FF" mode="Opaque">
<textField>
<reportElement x="0" y="0" width="50" height="25" />
<textFieldExpression><![CDATA[$V{SLA_PENALTY_APPLICABLEMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="50" columnTotalGroup="SLA_PENALTY_APPLICABLE1">
<cellContents backcolor="#BFE1FF" mode="Opaque">
<textField>
<reportElement x="0" y="0" width="50" height="25" />
<textFieldExpression><![CDATA[$V{SLA_PENALTY_APPLICABLEMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell rowTotalGroup="SLA_PENALTY_APPLICABLE" columnTotalGroup="SLA_PENALTY_APPLICABLE1">
<cellContents backcolor="#BFE1FF" mode="Opaque">
<textField>
<reportElement x="0" y="0" width="50" height="25" />
<textFieldExpression><![CDATA[$V{SLA_PENALTY_APPLICABLEMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
<componentElement>
<reportElement key="table" positionType="Float" x="0" y="60" width="180" height="60"/>
<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 Dataset 1" >
<datasetParameter name="ContractId">
<datasetParameterExpression><![CDATA[$P{ContractId}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="VersionNo">
<datasetParameterExpression><![CDATA[$P{VersionNo}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="180" >
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement positionType="Float" mode="Opaque" x="0" y="0" width="180" height="30" backcolor="#C9D9E7" />
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="8" isBold="true"/>
</textElement>
<text><![CDATA[Comments]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="30" rowSpan="1">
<textField isBlankWhenNull="true">
<reportElement positionType="Float" x="0" y="0" width="180" height="30" />
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="8" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{TERM_COMMENTS}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
<staticText>
<reportElement mode="Opaque" x="0" y="40" width="180" height="20" backcolor="#C9D9E7"/>
<textElement>
<font fontName="Arial" isBold="true"/>
</textElement>
<text><![CDATA[Temination charges for convenience]]></text>
</staticText>
</band>
</summary>
</jasperReport>
Set the property net.sf.jasperreports.export.xls.white.page.background to true in the report jrxml.
i.e.
<property name="net.sf.jasperreports.export.xls.white.page.background" value="false" />
The cause of strange behaviour of drawing color text
The JRXlsExporter has some limitations of using colours.
The snippet from source code of net.sf.jasperreports.engine.export.JRXlsExporter (I took source code of JR 6.3.0 version in this sample)
public void exportText(JRPrintText textElement, JRExporterGridCell gridCell, int colIndex, int rowIndex) throws JRException {
JRStyledText styledText = getStyledText(textElement);
if (styledText == null) {
return;
}
short forecolor = getWorkbookColor(textElement.getForecolor()).getIndex();
TextAlignHolder textAlignHolder = getTextAlignHolder(textElement);
short horizontalAlignment = getHorizontalAlignment(textAlignHolder);
short verticalAlignment = getVerticalAlignment(textAlignHolder);
short rotation = getRotation(textAlignHolder);
short mode = backgroundMode;
short backcolor = whiteIndex;
if (!Boolean.TRUE.equals(sheetInfo.ignoreCellBackground) && gridCell.getCellBackcolor() != null) {
mode = HSSFCellStyle.SOLID_FOREGROUND;
backcolor = getWorkbookColor(gridCell.getCellBackcolor()).getIndex();
}
The cause of using "wrong" colour is at getWorkbookColor(Color) method from the same class:
protected HSSFColor getWorkbookColor(Color awtColor) {
byte red = (byte)awtColor.getRed();
byte green = (byte)awtColor.getGreen();
byte blue = (byte)awtColor.getBlue();
HSSFColor color = null;
if (getCurrentConfiguration().isCreateCustomPalette()) {
try {
color = palette.findColor(red,green, blue) != null
? palette.findColor(red,green, blue)
: palette.addColor(red,green, blue);
} catch(Exception e) {
if(customColorIndex < MAX_COLOR_INDEX) {
palette.setColorAtIndex(customColorIndex, red, green, blue);
color = palette.getColor(customColorIndex++);
} else {
color = palette.findSimilarColor(red, green, blue);
}
}
}
return color == null ? getNearestColor(awtColor) : color;
}
The color is defined with help of getNearestColor(Color) method:
protected HSSFColor getNearestColor(Color awtColor) {
HSSFColor color = hssfColorsCache.get(awtColor);
if (color == null) {
int minDiff = Integer.MAX_VALUE;
for (Map.Entry<HSSFColor, short[]> hssfColorEntry : hssfColorsRgbs.entrySet()) {
HSSFColor crtColor = hssfColorEntry.getKey();
short[] rgb = hssfColorEntry.getValue();
int diff = Math.abs(rgb[0] - awtColor.getRed()) + Math.abs(rgb[1] - awtColor.getGreen()) + Math.abs(rgb[2] - awtColor.getBlue());
if (diff < minDiff) {
minDiff = diff;
color = crtColor;
}
}
hssfColorsCache.put(awtColor, color);
}
return color;
}
If color (backcolor) of element is not present at supported colours list at org.apache.poi.hssf.util.HSSFColor class of Apache POI library the "nearest" color will be used.
For grey color (for example, #F2F2F2) the nearest color can be white. In this case JRXlsExporter will draw text with white backcolor ignoring original backcolor of textField element.
The JRXlsxExporter does not have this problem.
How to solve problem?
As we can see the getWorkbookColor method has this check:
if (getCurrentConfiguration().isCreateCustomPalette()) {
What if we can turn on custom pallette? Yes, this will solve our problem - in this case the original color will be applied.
We can enable custom pallete with help of net.sf.jasperreports.export.xls.create.custom.palette property or with help of Java API. The SimpleXlsExporterConfiguration.setCreateCustomPalette(Boolean) method will do the same stuff as net.sf.jasperreports.export.xls.create.custom.palette property.
Working example
I took colors of standard palette in Excel from HSSFColor class and prepared jrxml demonstrated which colors are supported by JRXlsExporter out of box.
<?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="All supported colours by JRXlsExporter" pageWidth="960" pageHeight="595" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="960" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isIgnorePagination="true" >
<property name="net.sf.jasperreports.export.xls.create.custom.palette" value="true"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<title>
<band height="210">
<staticText>
<reportElement positionType="Float" mode="Opaque" x="0" y="10" width="960" height="25" forecolor="#000000" backcolor="#F2F2F2" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[All supported colours by JRXlsExporter]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="0" y="50" width="160" height="20" forecolor="#FFFFFF" backcolor="#000000" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[BLACK]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="0" y="70" width="160" height="20" forecolor="#FFFFFF" backcolor="#993300" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[BROWN]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="0" y="90" width="160" height="20" forecolor="#FFFFFF" backcolor="#333300" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[OLIVE_GREEN]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="0" y="110" width="160" height="20" forecolor="#FFFFFF" backcolor="#003300" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[DARK_GREEN]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="0" y="130" width="160" height="20" forecolor="#FFFFFF" backcolor="#003366" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[DARK_TEAL]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="0" y="150" width="160" height="20" forecolor="#FFFFFF" backcolor="#000080" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[DARK_BLUE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="0" y="170" width="160" height="20" forecolor="#FFFFFF" backcolor="#333399" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[INDIGO]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="0" y="190" width="160" height="20" forecolor="#FFFFFF" backcolor="#333333" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[GREY_80_PERCENT]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="160" y="50" width="160" height="20" forecolor="#FFFFFF" backcolor="#FF6600" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[ORANGE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="160" y="70" width="160" height="20" forecolor="#FFFFFF" backcolor="#808000" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[DARK_YELLOW]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="160" y="90" width="160" height="20" forecolor="#FFFFFF" backcolor="#008000" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[GREEN]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="160" y="110" width="160" height="20" forecolor="#FFFFFF" backcolor="#008080" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[TEAL]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="160" y="130" width="160" height="20" forecolor="#FFFFFF" backcolor="#0000FF" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[BLUE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="160" y="150" width="160" height="20" forecolor="#FFFFFF" backcolor="#666699" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[BLUE_GREY]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="160" y="170" width="160" height="20" forecolor="#FFFFFF" backcolor="#808080" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[GREY_50_PERCENT]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="160" y="190" width="160" height="20" forecolor="#FFFFFF" backcolor="#FF0000" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[RED]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="320" y="50" width="160" height="20" forecolor="#FFFFFF" backcolor="#FF9900" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[LIGHT_ORANGE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="320" y="70" width="160" height="20" forecolor="#FFFFFF" backcolor="#99CC00" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[LIME]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="320" y="90" width="160" height="20" forecolor="#FFFFFF" backcolor="#339966" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[SEA_GREEN]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="320" y="110" width="160" height="20" forecolor="#FFFFFF" backcolor="#33CCCC" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[AQUA]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="320" y="130" width="160" height="20" forecolor="#FFFFFF" backcolor="#3366FF" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[LIGHT_BLUE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="320" y="150" width="160" height="20" forecolor="#FFFFFF" backcolor="#800080" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[VIOLET]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="320" y="170" width="160" height="20" forecolor="#FFFFFF" backcolor="#969696" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[GREY_40_PERCENT]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="320" y="190" width="160" height="20" forecolor="#FFFFFF" backcolor="#FF00FF" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[PINK]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="480" y="50" width="160" height="20" forecolor="#FFFFFF" backcolor="#FFCC00" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[GOLD]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="480" y="70" width="160" height="20" forecolor="#000000" backcolor="#FFFF00" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[YELLOW]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="480" y="90" width="160" height="20" forecolor="#000000" backcolor="#00FF00" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[BRIGHT_GREEN]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="480" y="110" width="160" height="20" forecolor="#000000" backcolor="#00FFFF" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[TURQUOISE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="480" y="130" width="160" height="20" forecolor="#FFFFFF" backcolor="#800000" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[DARK_RED]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="480" y="150" width="160" height="20" forecolor="#FFFFFF" backcolor="#00CCFF" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[SKY_BLUE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="480" y="170" width="160" height="20" forecolor="#FFFFFF" backcolor="#993366" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[PLUM]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="480" y="190" width="160" height="20" forecolor="#FFFFFF" backcolor="#C0C0C0" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[GREY_25_PERCENT]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="640" y="50" width="160" height="20" forecolor="#FFFFFF" backcolor="#FF99CC" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[ROSE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="640" y="70" width="160" height="20" forecolor="#000000" backcolor="#FFFF99" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[LIGHT_YELLOW]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="640" y="90" width="160" height="20" forecolor="#000000" backcolor="#CCFFCC" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[LIGHT_GREEN]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="640" y="110" width="160" height="20" forecolor="#000000" backcolor="#CCFFFF" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[LIGHT_TURQUOISE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="640" y="130" width="160" height="20" forecolor="#000000" backcolor="#99CCFF" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[PALE_BLUE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="640" y="150" width="160" height="20" forecolor="#FFFFFF" backcolor="#CC99FF" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[LAVENDER]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="640" y="170" width="160" height="20" forecolor="#000000" backcolor="#FFFFFF" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[WHITE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="640" y="190" width="160" height="20" forecolor="#FFFFFF" backcolor="#9999FF" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[CORNFLOWER_BLUE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="800" y="50" width="160" height="20" forecolor="#000000" backcolor="#FFFFCC" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[LEMON_CHIFFON]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="800" y="70" width="160" height="20" forecolor="#FFFFFF" backcolor="#7F0000" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[MAROON]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="800" y="90" width="160" height="20" forecolor="#FFFFFF" backcolor="#660066" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[ORCHID]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="800" y="110" width="160" height="20" forecolor="#FFFFFF" backcolor="#FF8080" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[CORAL]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="800" y="130" width="160" height="20" forecolor="#FFFFFF" backcolor="#0066CC" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[ROYAL_BLUE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="800" y="150" width="160" height="20" forecolor="#000000" backcolor="#CCCCFF" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[LIGHT_CORNFLOWER_BLUE]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="800" y="170" width="160" height="20" forecolor="#000000" backcolor="#FFCC99" />
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[TAN]]></text>
</staticText>
</band>
</title>
</jasperReport>
At JSS (Jaspersoft Studio) the output result looks like this:
Without applying <property name="net.sf.jasperreports.export.xls.create.custom.palette" value="true"/> the generated xls file will be like this:
The textField with "All supported colours by JRXlsExporter" text has backcolor="#F2F2F2" attribute (this is grey color), but the text was generated without backcolor (color is white).
With custom pallete the generated result is:
As we can see applying custom palette has solved problem of JRXlsExporter.
If you have a parent report and a child report and you have set only in child, it will not work. Set the property in both parent and child report.

Rectangle borders are not displayed

I have a requirement where I need to display a section of data surrounded by borders, like this:
I have tried to do it with adding Rectangle component in the Background band. In the internal preview window and PDF preview it is displayed as above, but when I run it in the server or use HTML preview, the border disappears. I have also tried to insert the Rectangle component in the Detail band and using Frames instead of a Rectangle, surrounding the data, but with the same problem.
I am using iReport 5.0.1 with compatibility set to JasperReports 3.5.1.
Here is my jrxml file:
<?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="Payslip" pageWidth="1000" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="960" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<import value="org.joda.time.DateTime"/>
<style name="Headings" vAlign="Middle" lineSpacing="1_1_2" fontName="Arial" fontSize="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
<style name="Data" isDefault="true" vAlign="Middle" lineSpacing="1_1_2" fontName="Arial" fontSize="11"/>
<parameter name="rptName" class="java.lang.String" isForPrompting="false"/>
<parameter name="company" class="java.lang.String"/>
<field name="empName" class="java.lang.String"/>
<field name="salaryMonthName" class="java.lang.String"/>
<field name="salaryMonthYear" class="java.lang.Integer"/>
<field name="employeeCode" class="java.lang.String"/>
<field name="designation" class="java.lang.String"/>
<field name="grade" class="java.lang.String"/>
<field name="location" class="java.lang.String"/>
<field name="department" class="java.lang.String"/>
<field name="branch" class="java.lang.String"/>
<field name="dateOfJoining" class="org.joda.time.DateTime"/>
<field name="pfNumber" class="java.lang.String"/>
<field name="panNumber" class="java.lang.String"/>
<field name="bankName" class="java.lang.String"/>
<field name="accountNumber" class="java.lang.String"/>
<field name="workingDays" class="java.lang.Double"/>
<field name="paidDays" class="java.lang.Double"/>
<field name="absentDays" class="java.lang.Double"/>
<background>
<band height="301">
<rectangle>
<reportElement mode="Transparent" x="0" y="120" width="324" height="165"/>
<graphicElement>
<pen lineWidth="2.0"/>
</graphicElement>
</rectangle>
<rectangle>
<reportElement mode="Transparent" x="324" y="120" width="320" height="165"/>
<graphicElement>
<pen lineWidth="2.0"/>
</graphicElement>
</rectangle>
</band>
</background>
<title>
<band height="102">
<line>
<reportElement x="0" y="43" width="265" height="1" forecolor="#3333FF"/>
<graphicElement>
<pen lineWidth="3.0"/>
</graphicElement>
</line>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="405" height="32" forecolor="#3333FF"/>
<textElement lineSpacing="Single">
<font size="16" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{company}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="44" width="200" height="31" forecolor="#3333FF"/>
<textElement lineSpacing="Single">
<font fontName="Arial" size="18"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{rptName}]]></textFieldExpression>
</textField>
<textField pattern="EEE, d MMM yyyy HH:mm">
<reportElement mode="Opaque" x="843" y="71" width="117" height="20" forecolor="#FFFFFF" backcolor="#999999"/>
<textElement lineSpacing="Single">
<font fontName="Arial"/>
</textElement>
<textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
<textField>
<reportElement x="92" y="82" width="129" height="20"/>
<textElement lineSpacing="Single">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{salaryMonthName} + " " + $F{salaryMonthYear}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="82" width="92" height="20"/>
<textElement lineSpacing="Single">
<font size="14" isBold="true"/>
</textElement>
<text><![CDATA[For Month]]></text>
</staticText>
</band>
</title>
<detail>
<band height="205">
<staticText>
<reportElement style="Headings" x="12" y="23" width="91" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[Code]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="12" y="43" width="91" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="12" y="63" width="91" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[Designation]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="12" y="83" width="91" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[Grade]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="12" y="103" width="91" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[Location]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="12" y="123" width="91" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[Department]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="12" y="143" width="91" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[Branch]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="12" y="163" width="92" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[Date of Joining]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="341" y="23" width="98" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[P. F. Number]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="341" y="43" width="98" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[PAN No.]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="341" y="63" width="98" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[Pay Mode / Bank Name]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="341" y="83" width="98" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[A/C No.]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="341" y="103" width="98" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[Working Days]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="341" y="123" width="98" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[Paid Days]]></text>
</staticText>
<staticText>
<reportElement style="Headings" x="341" y="143" width="98" height="20"/>
<textElement lineSpacing="1_1_2"/>
<text><![CDATA[Absent Days]]></text>
</staticText>
<textField>
<reportElement x="154" y="23" width="140" height="20"/>
<textElement lineSpacing="Single"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{employeeCode}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="154" y="43" width="140" height="20"/>
<textElement lineSpacing="Single"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{empName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="154" y="63" width="140" height="20"/>
<textElement lineSpacing="Single"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{designation}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="154" y="83" width="140" height="20"/>
<textElement lineSpacing="Single"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{grade}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="154" y="103" width="140" height="20"/>
<textElement lineSpacing="Single"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{location}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="154" y="123" width="140" height="20"/>
<textElement lineSpacing="Single"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{department}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="154" y="143" width="140" height="20"/>
<textElement lineSpacing="Single"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{branch}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="492" y="23" width="140" height="20"/>
<textElement lineSpacing="1_1_2"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{pfNumber}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="492" y="43" width="140" height="20"/>
<textElement lineSpacing="1_1_2"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{panNumber}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="492" y="63" width="140" height="20"/>
<textElement lineSpacing="1_1_2"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{bankName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="492" y="83" width="140" height="20"/>
<textElement lineSpacing="1_1_2"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{accountNumber}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="492" y="103" width="140" height="20"/>
<textElement lineSpacing="1_1_2"/>
<textFieldExpression class="java.lang.Double"><![CDATA[$F{workingDays}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="492" y="123" width="140" height="20"/>
<textElement lineSpacing="1_1_2"/>
<textFieldExpression class="java.lang.Double"><![CDATA[$F{paidDays}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="492" y="143" width="140" height="20"/>
<textElement lineSpacing="1_1_2"/>
<textFieldExpression class="java.lang.Double"><![CDATA[$F{absentDays}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="154" y="163" width="140" height="20"/>
<textElement lineSpacing="1_1_2"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{dateOfJoining}.toString("dd-MMM-yyyy")]]></textFieldExpression>
</textField>
<break>
<reportElement x="0" y="184" width="960" height="1"/>
</break>
</band>
</detail>
</jasperReport>
The problem that you are having may be due to the fact that you cannot have objects overlapping in HTML. I have had this issue with Jasper before. If two objects (or more) overlap, only one of them will show on the report.
You could try using separate lines that do not overlap any of the other objects.
I have had trouble getting that to work so the way I have dealt with the situation in cases like yours is to use the borders of the text fields to make up the rectangles. For the top left label (Code), you can use it's top and left borders. For the middle labels, the left border. And for the bottom field (Date of Joining), the bottom and left borders. Then the opposite for the text fields. Then you can use padding on your text fields to make them look right. Sometimes I have a padding of 20 or more to get the effect I'm looking for.
I hope this helps.

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>

ireport generates pdf and html report with different look and feel? Html and Pdf report not generated with same format

I am using jasper report in my liferay custom portlet and i designed my report with ireport 4.7.1 but my problem is why there is vast diffrence in the reports generated with html and with pdf..there is lots of diffrence in rows of reports in html format and pdf format..how can i make both the html and pdf report generated from same jasper file as identical.?i mean with same look and feel..
following are my snippet of html and pdf report
HTML REPORT
PDF REPORT
following is my jrxml file from which i generate .jasper and then generating above two result.
<?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="Campaign_Advertise_DateRange_Report" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true">
<property name="ireport.zoom" value="0.9090909090909098"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="Table Dataset 1"/>
<field name="advertisename" class="java.lang.String"/>
<field name="camp_name" class="java.lang.String"/>
<field name="ad_location" class="java.lang.String"/>
<field name="clicked" class="java.lang.Integer"/>
<field name="impression" class="java.lang.Integer"/>
<field name="filter_start_date" class="java.util.Date"/>
<field name="filter_end_date" class="java.util.Date"/>
<variable name="CamapignTotal" class="java.lang.Integer" resetType="Group" resetGroup="Campaign Name" calculation="Sum">
<variableExpression><![CDATA[$F{impression}]]></variableExpression>
</variable>
<variable name="CampaignGrandTotal" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{impression}]]></variableExpression>
</variable>
<group name="Campaign Name">
<groupExpression><![CDATA[$F{camp_name}]]></groupExpression>
<groupFooter>
<band height="21">
<textField pattern="" isBlankWhenNull="true">
<reportElement style="table_TD" x="419" y="0" width="86" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{CamapignTotal}]]></textFieldExpression>
</textField>
<staticText>
<reportElement style="table_TD" x="346" y="0" width="73" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[Group Total :]]></text>
</staticText>
</band>
</groupFooter>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="114">
<staticText>
<reportElement x="136" y="24" width="283" height="67"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="32" isUnderline="true"/>
</textElement>
<text><![CDATA[Campaign Reports]]></text>
</staticText>
<staticText>
<reportElement x="0" y="2" width="30" height="20"/>
<textElement>
<font fontName="Times New Roman" isBold="true"/>
</textElement>
<text><![CDATA[Date : ]]></text>
</staticText>
<textField pattern="MM/dd/yyyy">
<reportElement x="30" y="2" width="100" height="20"/>
<textElement textAlignment="Justified">
<font fontName="Times New Roman" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="94" width="30" height="20"/>
<textElement textAlignment="Right">
<font isBold="true"/>
</textElement>
<text><![CDATA[From:]]></text>
</staticText>
<staticText>
<reportElement x="136" y="94" width="19" height="20"/>
<textElement textAlignment="Right">
<font isBold="true"/>
</textElement>
<text><![CDATA[To:]]></text>
</staticText>
<textField>
<reportElement x="30" y="94" width="96" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{filter_start_date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="155" y="94" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{filter_end_date}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="419" y="94" width="131" height="20"/>
<textElement textAlignment="Right">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Advertise Display Reports]]></text>
</staticText>
<image>
<reportElement x="458" y="8" width="92" height="53"/>
<imageExpression><![CDATA["D:\\Liferay\\liferay-plugins-sdk-6.1.1-ce-ga2-20120731132656558\\liferay-plugins-sdk-6.1.1\\portlets\\eMenuAdvertise-portlet\\docroot\\img\\eMenuLogo.png"]]></imageExpression>
</image>
</band>
</title>
<pageHeader>
<band height="52">
<staticText>
<reportElement style="table_TD" mode="Transparent" x="0" y="31" width="100" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[Advertise Name]]></text>
</staticText>
<staticText>
<reportElement style="table_TD" mode="Transparent" x="346" y="31" width="73" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[Clicked]]></text>
</staticText>
<staticText>
<reportElement style="table_TD" mode="Transparent" x="250" y="31" width="96" height="20" isPrintInFirstWholeBand="true"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[AD Location]]></text>
</staticText>
<staticText>
<reportElement style="table_TD" mode="Transparent" x="100" y="31" width="150" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[Campaign Name]]></text>
</staticText>
<staticText>
<reportElement style="table_TD" mode="Transparent" x="419" y="31" width="86" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[Impression]]></text>
</staticText>
</band>
</pageHeader>
<detail>
<band height="21" splitType="Immediate">
<textField>
<reportElement style="table_TD" mode="Transparent" x="0" y="-1" width="100" height="22"/>
<textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
<font fontName="Times New Roman"/>
</textElement>
<textFieldExpression><![CDATA[$F{advertisename}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_TD" mode="Transparent" x="250" y="-1" width="96" height="22" backcolor="#FFFFFF"/>
<textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
<font fontName="Times New Roman"/>
</textElement>
<textFieldExpression><![CDATA[$F{ad_location}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_TD" mode="Transparent" x="419" y="-1" width="86" height="22"/>
<textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
<font fontName="Times New Roman"/>
</textElement>
<textFieldExpression><![CDATA[$F{impression}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_TD" mode="Transparent" x="100" y="-1" width="150" height="22"/>
<textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
<font fontName="Times New Roman"/>
</textElement>
<textFieldExpression><![CDATA[$F{camp_name}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_TD" mode="Transparent" x="346" y="-1" width="73" height="22"/>
<textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
<font fontName="Times New Roman"/>
</textElement>
<textFieldExpression><![CDATA[$F{clicked}]]></textFieldExpression>
</textField>
</band>
</detail>
<lastPageFooter>
<band height="50">
<staticText>
<reportElement style="table_TD" x="346" y="0" width="73" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[Grand Total :]]></text>
</staticText>
<textField isBlankWhenNull="false">
<reportElement style="table_TD" x="419" y="0" width="86" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{CampaignGrandTotal}]]></textFieldExpression>
</textField>
</band>
</lastPageFooter>
</jasperReport>
Can any one help me out to make both reports look and feel same ?
The problem in your report seems to be the height of the elements in the Detail Band, they're 22 pixels, and the band is 21, also their top property is -1, i recommend you to make the band bigger (or your controls smaller) and set the Top property to 0, or any positive value.