2

I want to make some text in a text field bold. I visited http://jasperreports.sourceforge.net/sample.reference/markup/index.html but could not get the desired result. I am using text field right now but when I tried using styled/html, the compilation failed. So can you help me with this jrxml code snippet:

<textField>
    <reportElement x="200" y="10" width="590" height="42"/>
    <textElement markup="styled"/>
    <textFieldExpression><![CDATA["The static text without any format.\nThe field's data with bold format<style isBold='true'>:" + $F{TASKS_SUBTASK} + "</style>\n<style isBold='true' isItalic='true' isUnderline='true'>The static underlined text with bold and italic format</style>"]]></textFieldExpression>
</textField>

In this example: Style a text field in Jasper, the text field expression is wrong for which compilation fails.

Your help will be appreciated.

Community
  • 1
  • 1
Anil
  • 1,470
  • 5
  • 24
  • 35

6 Answers6

5

This work good:

"<style isBold='true' pdfFontName='Helvetica-Bold'>" + $F{data} + "</style>"

for input data from datasource, or

<style isBold="true" pdfFontName="Helvetica-Bold">Bolt text</style>

only for some static text.

For Text-field set properties Markup = styled.

Androdos
  • 653
  • 8
  • 11
4

in your view ireport designer.

click on the field and in the properties panel.: markup = styled selected

Right click on the fied. edit expression:

($F{fila1}.equals("c") ? "<style forecolor='red'>"+ $F{fila1}+"</style>" : $F{fila1})

or xml

<textFieldExpression><![CDATA[($F{fila1}.equals("c") ? "<style forecolor='red'>"+ $F{fila1}+"</style>" : $F{fila1})]]></textFieldExpression>
Edy Aguirre
  • 2,113
  • 20
  • 20
2

The <b> </b> tags no longer work on text fields. Make sure that 'Styled text' is enabled for the text field and put this in the field expression.

<style isBold="true" pdfFontName="Helvetica-Bold">Text to be bold...</style>

The pdfFontName can be whatever you like.

If you are making text bold that is already in a string be sure to escape the above quotes with a backslash.

Mark
  • 158
  • 5
1

I solved this problem changing 'makup' text-field atribute to 'html'. Then in text-field expression use html tags like < b> < /b>. =D

1

I solved by putting for bold and underline in input string

"<b><u> your text</u></b>"
Anil
  • 1,470
  • 5
  • 24
  • 35
0
"<style isBold='true' pdfFontName='Helvetica-Bold'>" + $F{data} + "</style>"

what is done above simply

<style isBold="true" pdfFontName="Helvetica-Bold">Bolt text</style>

For Text-field set properties Markup = styled.


see the screenshot below hope this helps !!!

enter image description here

Akitha_MJ
  • 3,882
  • 25
  • 20