Skip to content Skip to sidebar Skip to footer

Jasper Report : Aligning Text As Center In Text Field Using Html Markup

I have created a Jasper Report to display text retrieved from DB. The text is in the HTML format. I have a requirement to style and align the text when displaying in PDF. This is a

Solution 1:

Font size

I can't see nothing wrong with your font size command, make sure that you have markup="html" and that the " is escaped properly you can try be replacing it with '

This textFieldExpression

<textField><reportElementx="132"y="0"width="126"height="30"uuid="0328a547-49c7-402c-bcb0-ae2a8fba4fb3"/><textElementmarkup="html"/><textFieldExpression><![CDATA["<p><font size=\"1\">Small</font>&nbsp;<font size=\"3\">Big</font></p>"]]></textFieldExpression></textField>

will render

small BIG

Text alignment

with different markup (styled,rtf,html) you can only format how the text looks (color,bold,underline ecc).

This feature is for producing styled text.

Quoting Teodord (jasper report staff)

The alignment is not among supported styling because it is not about how text characters look, but about how you lay them out. We cannot change the alignment of text within the same text field element.

What are you options?

  1. Left padding text with space, you could create your own static method that left pad your text with es. &nbsp; depending on the text length.

  2. Try the <hc:html> component, this will render an image of you html. (not text anymore but image...)

  3. Post process the JasperReport or JasperPrint to move the element... (note it needs to be a separate element)

not much.. so why not do without....

Post a Comment for "Jasper Report : Aligning Text As Center In Text Field Using Html Markup"