4

I'm working with Jasperrerports 3.5.1 and I have a html-styled text that I need to be printed in a PDF with the proper styles.

In the cell I want to print the styled text I have the markup property set to "HTML". I have created a this sample text:

<p>
<table border="0">
<tbody>
<tr>
<td>wewewe</td>
<td>eeeee</td>
</tr>
<tr>
<td>qwewewq</td>
<td>3333333</td>
</tr>
</tbody>
</table>
</p>
<p>4444</p>

but in the PDF it is printed as if, without any formatting. Do you know how can I use html styles here, because using tables inside cells are one of the client's requeriments.

Thanks.

2
  • How are you printing to PDF? Are you using File > Print?
    – Rowan
    Commented Aug 19, 2009 at 13:21
  • Well, I meant when I get the PDF created. I don't print the pdf but create it with jasperreport. Sorry for the mistake but I sometimes don't get the proper word in english.
    – Averroes
    Commented Aug 27, 2009 at 11:39

3 Answers 3

3

I know this question is old, but JasperReports only supports a small, very small set of HTML tags for styling. The list I found of those tags is:

b
br
font
u
i
sup
sub
li

See here for more info.

0

First, I'm not sure if case matters but make sure the value of the markup attribute for your textElement element in your JRXML is set to "html" (lowercase).

Second, the purpose of the markup attribute is to format text using HTML, it is meant to make text bold, italic, change font color or size, etc. Creating a table is not what this attribute is for.

You can create tables using standard JRXML, without resorting to embedding HTML, an example is bundled with the JasperReports download under ${JASPERREPORTS_HOME}/demo/samples/table

0

You can do something like

<textField >
            <reportElement x="7" y="10" width="543" height="53"/>
            <textElement markup="html">
                <font size="10" pdfFontName="Helvetica" isPdfEmbedded="true"/>
            </textElement>
            <textFieldExpression class="java.lang.String"><![CDATA[$F{myElementName}]]></textFieldExpression>
        </textField>

Then you can pass the following string programatically

<p style="color:red">
<table border="0">
<tbody>
<tr>
<td style="border: 1px solid">wewewe</td>
<td style="border: 1px solid">eeeee</td>
</tr>
<tr>
<td style="border: 1px solid" >qwewewq</td>
<td style="border: 1px solid">3333333</td>
</tr>
</tbody>
</table>
</p>
<p>4444</p>

I haven't found yet how to create css to apply it using classes inside a jasperreport text element.

Not the answer you're looking for? Browse other questions tagged or ask your own question.