0

I want to add tab to a text field in my Jasper template. Below is my text field.

<staticText>
    <reportElement key="" style="Table_CH" positionType="Float" x="0" y="37" width="802" height="112" uuid="db0d6ece-871a-4e7d-8f74-0abca53b1280"/>
    <textElement markup="styled">
        <font fontName="SansSerif" size="8" isBold="false"/>
        <paragraph lineSpacing="Single"/>
    </textElement>
    <text>
        <![CDATA[ Reader - please note: <li>List element1</li><li>List element2</li>]]>
    </text>
</staticText>

I want to place a tab before each list element.

Alex K
  • 22,315
  • 19
  • 108
  • 236
Nevin
  • 769
  • 1
  • 11
  • 26
  • 2
    Why none of your questions have accepted answer? Does none of the answers resolve your problem? – Viki888 Mar 02 '17 at 14:12
  • yes @Viki888, still working on it. If it works I will mark the correct one which worked for me. – Nevin Mar 02 '17 at 22:40

2 Answers2

2

The adding tab symbol after the bullet can be done is several ways:

  • using \t (tab) sybmol
  • using &#09; to rendering tab in html code
  • using &emsp; character entity

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="Tabs sample" pageWidth="842" pageHeight="595" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="583" leftMargin="2" rightMargin="10" topMargin="2" bottomMargin="2">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <title>
        <band height="283">
            <textField>
                <reportElement positionType="Float" x="10" y="20" width="802" height="53" />
                <textElement markup="styled"/>
                <textFieldExpression><![CDATA["List without tabs:<li>List element1</li><li>List element2</li>"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement positionType="Float" x="10" y="90" width="802" height="53" />
                <textElement markup="styled"/>
                <textFieldExpression><![CDATA["List with basic tab:<li>\tList element1</li><li>\tList element2</li>"]]></textFieldExpression>
            </textField>

            <textField>
                <reportElement positionType="Float" x="10" y="160" width="802" height="53" />
                <textElement markup="html"/>
                <textFieldExpression><![CDATA["List with html tab:<li>&#09;List element1</li><li>&#09;List element2</li>"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement positionType="Float" x="10" y="230" width="802" height="53" />
                <textElement markup="html"/>
                <textFieldExpression><![CDATA["List with emsp tab:<li>&emsp;List element1</li><li>&emsp;List element2</li>"]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

Please note that I used textField for showing \t symbol.

Output result

The result in Jaspersoft Studio will be:

The preview in JSS


More info:

Community
  • 1
  • 1
Alex K
  • 22,315
  • 19
  • 108
  • 236
0

For adding spaces before bullet you can use html component with real html code. This component is not supplying complex html codes, only basic ones.

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="Html component" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <parameter name="htmlCode" class="java.lang.String">
        <defaultValueExpression><![CDATA["<div>\n" +
                    "<h3>List of elements</h3>\n" +
                    "<ul>\n" +
                    "<li>element1</li>\n" +
                    "<li>element2</li>\n" +
                    "<li>element3</li>\n" +
                    "</ul>\n" +
                    "</div>"]]></defaultValueExpression>
    </parameter>
    <title>
        <band height="742">
            <componentElement>
                <reportElement x="0" y="0" width="190" height="70"/>
                <hc:html xmlns:hc="http://jasperreports.sourceforge.net/htmlcomponent" xsi:schemaLocation="http://jasperreports.sourceforge.net/htmlcomponent http://jasperreports.sourceforge.net/xsd/htmlcomponent.xsd" scaleType="RealHeight" horizontalAlign="Left" verticalAlign="Top">
                    <hc:htmlContentExpression><![CDATA[$P{htmlCode}]]></hc:htmlContentExpression>
                </hc:html>
            </componentElement>
        </band>
    </title>
</jasperReport>

I've used parameter for setting html code for showing list. You can play with code for getting better result.

Output result

The result in Jaspersoft Studio will be:

The preview in JSS


More info:

Community
  • 1
  • 1
Alex K
  • 22,315
  • 19
  • 108
  • 236
  • net.sf.jasperreports.engine.JRRuntimeException: Unknown entity http://jasperreports.sourceforge.net/xsd/htmlcomponent.xsd, not loading. Looks like the xsd file doesn't exist anymore. I am searching for an alternative – Nevin Mar 02 '17 at 00:46
  • Where did you get this error? From Java code? Did you check the first link? You should add `htmlcomponent.jar` to cp in case using Java code – Alex K Mar 02 '17 at 09:31