Search code examples
jasper-reports

Display html in jasper reports (static) text field


I have this text in a static text field in jasper reports jrxml

<div style='width: 200px;height: 200px; border: 5px solid red; background-color:red'></div>

If I style the field as 'None', i can see the raw html in preview, however, if I style it as html, then nothing is displayed all all. Obviously its a 200px x 200px red box with a black 5px border. Is there something i can do to have this html displayed inpreview?


Solution

  • Markup is responsible for text representation only. There is only a limited set of supported markup tags listed at JasperReports Ultimate Guide:

    • <b>
    • <u>
    • <i>
    • <font>
    • <sup>
    • <sub>
    • <li>
    • <br>

    As you can see they are all related to text formatting.

    If you need a red square you can draw it manually by adding rectangle with needed background color and border. Lightly modified example of rectangle element from the same guide:

      <rectangle>
        <reportElement x="0" y="350" width="200" height="200" backcolor="#ff0000"/>
        <graphicElement>
          <pen lineWidth="2"/>
        </graphicElement>
      </rectangle>