snafua
snafua

Reputation: 75

How to print html content to a PDF with jasper reports?

I'm using Primefaces 5.3 in a web app along with the Primefaces <p:editor> which saves its data to a database table. I would like to export/print to PDF the value data from the database with the format being ready instead of printing out codes like

<br> or <ul> <li>, etc.

I'm using Jasper reports to create the report and then exporting to pdf, so I need to create "something" that can be printed with jasper reports that will take care of the html codes.

Upvotes: 1

Views: 5755

Answers (1)

Petter Friberg
Petter Friberg

Reputation: 21710

You can use the HtmlComponent <hc:html/>

Example

<componentElement>
    <reportElement x="0" y="100" width="230" height="110" backcolor="#ADD8E6" uuid="332dd551-e8cd-4cb0-a11f-7325f481017b"/>
    <hc:html xmlns:hc="http://jasperreports.sourceforge.net/htmlcomponent" xsi:schemaLocation="http://jasperreports.sourceforge.net/htmlcomponent http://jasperreports.sourceforge.net/xsd/htmlcomponent.xsd" scaleType="FillFrame" horizontalAlign="Left" verticalAlign="Top">
        <hc:htmlContentExpression><![CDATA["Hello<br/>World"]]></hc:htmlContentExpression>
    </hc:html>
</componentElement>

It will generate an image of your html.

Upvotes: 2

Related Questions