views:

1360

answers:

2

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.

A: 

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

Ensode
A: 

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.

jaime