unleashed
unleashed

Reputation: 331

How to prevent wrapping of a line of text in Jasperreports

I have a line of text which reads "International ID". But whenever I am to display in in my Jasperreport to PDF, it will sometimes be spread across two lines like this: "International ID". Is there a way to prevent wrapping in like in html I would use

<span style="white-space: nowrap">Long line with no breaks</span> 

Upvotes: 2

Views: 5761

Answers (3)

zellers
zellers

Reputation: 185

Jasperreports appears to be honoring &nbsp; combined with <textElement markup="html"/>

Example:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.20.0.final using JasperReports Library version 6.1.1  -->
<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="nbsp" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="77c97c1b-90ba-40a8-a5c3-f88b8a48a585">
    <title>
        <band height="130">
            <textField>
                <reportElement x="69" y="23" width="141" height="30" uuid="cd0cc386-988e-422f-83ba-744ee7d32d7d"/>
                <textFieldExpression><![CDATA["The quick brown fox jumps over the lazy dog"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="70" y="80" width="140" height="30" uuid="9b26682f-8ebd-4b40-87d3-f1c9827eedfd"/>
                <textElement markup="html"/>
                <textFieldExpression><![CDATA["The quick brown fox jumps&nbsp;over the lazy dog"]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

Upvotes: 0

Robert Kamphorst
Robert Kamphorst

Reputation: 1

My approach was this: (Excel nowrap in Jasper Report)

<reportElement key="staticText-5" mode="Opaque" x="0" y="70" width="100" height="15" backcolor="#FFFFFF">
<property name="net.sf.jasperreports.text.truncate.at.char" value="true"/>
          <property name="net.sf.jasperreports.export.xls.wrap.text" value="false"/>
</reportElement>

Upvotes: 0

keenUser
keenUser

Reputation: 1319

Give sufficient width to the field "International ID" so that it won't wrap up in any exported format. Also check this with different languages (If you are supporting multiple languages).

About the HTML text part, you can style textField elements using different markups like "Styled", "HTML", "RTF" etc. See Style a text field in JasperReports for details.

However, HTML markup supports very basic HTML tags like <p>, <br>, <color> etc. It won't support style="white-space: nowrap".

So you can either:

  1. Increase the width of textField OR
  2. Let the text cut-off by setting isStretchWithOverflow="false" (This is not recommended mostly)

Upvotes: 1

Related Questions