Hi

For a report , the requirements where that the text within the “Textfield” needed to consist of ; Bold, normal style, color and cursive as can seen below.
Demo1

The default options for style conditions would not allow me to achieve this requirement.
After some investigation I found the option: “Markup=HTML”
I would like to share this not so known feature of Jasper Reports and help others.

Hope you may find it useful.

Software used to Test this example : 
1) Jasper Design Studio 6.2 CE  you can use professional also.
2) Empty Data source.
3) Jasper Server is not taken to test it.
I Will provide 2 options how to work with the “Markup=HTML”

Steps :
1) Create a JRXML report as usual with a JDBC data source and in the report properties select when  no data type= All sections, No detail. ( I used a oracle XE dataconnection)

2)
# Go to “Dataset and Query dialog” and paste the following code

SELECT
'1. COMPLETE the Returns Form. Fill in the items you would like to return and indicate the reason for return using the return reason codes. Then simply detach this part of the form.'  AS  LBL_INSTRUCT_1,
'2. ENCLOSE this portion of the Returns Form in your return package. *Please keep the upper portion of this form, the Delivery Summary, for your records.' AS  LBL_INSTRUCT_2,
'3. VISIT the Returns & Exchanges page on our website, follow the instructions, and print your FREE returns shipping label. If you are not able to access or print the label, please reach out to us at customer@emailaddress.com or 757-663-4480.' AS LBL_INSTRUCT_3,
'4. SHIP this package back to us. Please note down the tracking number of your return parcel.' AS LBL_INSTRUCT_4
FROM
DUAL

# Drag and drop “Fields” element from “Outline/Report Inspector”  to “Title” band.
Adjust height and width of each element to w 254 px x h 70 px. And the title band height to 160px
# Preview should give you the following example:demo4
# Go back to “Design”
# Select each “Text Field” and go to its properties and set:  Markup = html
demo5

3)EXAMPLE : “TextField”  with expression

# Select each “TextField” and give below expression in it.
“+$F{LBL_INSTRUCT_1}+”
“+$F{LBL_INSTRUCT_2}+”
“+$F{LBL_INSTRUCT_3}+”

NOTE :
 As the lines of code is enclosed in double quotes the sentences inside them work as “JAVA” language strings
NOTE : http://www.w3schools.com/html/html_formatting.asp  for various html codes.

# Preview should give you the following example:

demo6 

4)EXAMPLE :  HTML code in SQL
In example 3 we added HTML code in the expression.
It is also possible to add the “HTML code” in the SQL code

# Remove all the expressions we created in “3 Example TextField  with expression “ for each “TextField”
# Go to “Dataset and Query dialog” and paste the following code

SELECT
'<b>1. COMPLETE </b>the Returns Form. Fill in the items you would like to return and indicate the reason for return using the return reason codes. Then simply detach this part of the form.' AS LBL_INSTRUCT_1,
'<b>2. ENCLOSE </b> this portion of the Returns Form in your return package. *Please keep the upper portion of this form, the Delivery Summary, for your records.' AS LBL_INSTRUCT_2,
'<b>3. VISIT </b>the <i>Returns & Exchanges </i>page on our website, follow the instructions, and print your <b>FREE</b> returns shipping label. If you are not able to access or print the label, please reach out to us at <span style="color:#80BFFF">customer@emailaddress.com</span> or <span style="color:#80BFFF">757-663-4480</span>.' AS LBL_INSTRUCT_3,
'<b>4. SHIP </b>this package back to us. Please note down the tracking number of your return parcel.' AS LBL_INSTRUCT_4
FROM
DUAL

# Save the report and preview
# Sample output will look like as shown in image in the beginning.demo7
The possibilities are numerous as you can imagine, especially in combination with the Jaspersoft styling options

Feel free to click on share

Kind regards
Martijn Bergevoet

References:
1) http://jasperreports.sourceforge.net/sample.reference/markup/
2) http://jasper-bi-suite.blogspot.com/2015/12/tip-half-colored-text-in-static-text.html

JRXML

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-10-06T13:43:41 -->
<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="Demo_Markup_HTML" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="4d5ea8a9-3818-4285-bfe0-96803385a06f">
 <property name="com.jaspersoft.studio.data.defaultdataadapter" value="DEMO_DB"/>
 <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
 <property name="ireport.zoom" value="1.0"/>
 <property name="ireport.x" value="0"/>
 <property name="ireport.y" value="0"/>
 <queryString>
 <![CDATA[SELECT
'<b>1. COMPLETE </b>the Returns Form. Fill in the items you would like to return and indicate the reason for return using the return reason codes. Then simply detach this part of the form.' AS LBL_INSTRUCT_1,
'<b>2. ENCLOSE </b> this portion of the Returns Form in your return package. *Please keep the upper portion of this form, the Delivery Summary, for your records.' AS LBL_INSTRUCT_2,
'<b>3. VISIT </b>the <i>Returns & Exchanges </i>page on our website, follow the instructions, and print your <b>FREE</b> returns shipping label. If you are not able to access or print the label, please reach out to us at <span style="color:#80BFFF">customer@emailaddress.com</span> or <span style="color:#80BFFF">757-663-4480</span>.' AS LBL_INSTRUCT_3,
'<b>4. SHIP </b>this package back to us. Please note down the tracking number of your return parcel.' AS LBL_INSTRUCT_4
FROM
DUAL]]>
 </queryString>
 <field name="LBL_INSTRUCT_1" class="java.lang.String"/>
 <field name="LBL_INSTRUCT_2" class="java.lang.String"/>
 <field name="LBL_INSTRUCT_3" class="java.lang.String"/>
 <field name="LBL_INSTRUCT_4" class="java.lang.String"/>
 <background>
 <band splitType="Stretch"/>
 </background>
 <title>
 <band height="160" splitType="Stretch">
 <property name="com.jaspersoft.studio.data.defaultdataadapter" value="DEMO_DB"/>
 <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
 <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
 <textField>
 <reportElement x="0" y="0" width="254" height="70" uuid="f06a015a-3486-42cb-9f38-5a292a5b56ca">
 <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
 <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
 </reportElement>
 <textElement markup="html"/>
 <textFieldExpression><![CDATA[$F{LBL_INSTRUCT_1}]]></textFieldExpression>
 </textField>
 <textField>
 <reportElement x="280" y="0" width="254" height="70" uuid="cff976b7-02ee-4fa1-8bd5-a3c4b61e14d3">
 <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
 <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
 </reportElement>
 <textElement markup="html"/>
 <textFieldExpression><![CDATA[$F{LBL_INSTRUCT_2}]]></textFieldExpression>
 </textField>
 <textField>
 <reportElement x="0" y="80" width="254" height="70" uuid="66b6da82-50f3-492d-a53c-0fc1599b0965">
 <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
 <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
 </reportElement>
 <textElement markup="html"/>
 <textFieldExpression><![CDATA[$F{LBL_INSTRUCT_3}]]></textFieldExpression>
 </textField>
 <textField>
 <reportElement x="280" y="80" width="254" height="70" uuid="50962dcf-05a9-4333-aa2a-072315db6534">
 <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
 </reportElement>
 <textElement markup="html"/>
 <textFieldExpression><![CDATA[$F{LBL_INSTRUCT_4}]]></textFieldExpression>
 </textField>
 </band>
 </title>
 <pageHeader>
 <band height="35" splitType="Stretch"/>
 </pageHeader>
 <columnHeader>
 <band height="61" splitType="Stretch"/>
 </columnHeader>
 <detail>
 <band height="125" splitType="Stretch"/>
 </detail>
 <columnFooter>
 <band height="45" splitType="Stretch"/>
 </columnFooter>
 <pageFooter>
 <band height="54" splitType="Stretch"/>
 </pageFooter>
 <summary>
 <band height="42" splitType="Stretch"/>
 </summary>
</jasperReport>

Advertisements