Search code examples
htmljasper-reportsprimefaces-extensions

How to use RTF content is jasper report


I am using Jasper Report 5.6.0 + JSF 2.2 + Primefaces 5.2

My problem is in detail band (content) of the jrxml I am passing RTF from pe:ckEditor here. This editor have many rich components e.g. tables, radio, fonts etc.

In generated document many styles escaped automatically. like table or font. While that text-field markup is html.

More: font will be changed if i generate html instead of pdf. and my rough guess is if any font that is not in JasperReport -> iText library it will escaped automatically


Solution

  • To render RTF text you use markup="rtf" on the textElement, however you will not be able to render tables, text alignment, box's ecc.

    This feature is only for producing styled text., how the text looks (bold, size, color ecc.)

    What are your options?

    1. Convert to html and use the HTML Renderer Component, note neither this is perfect since it will renderer and image of your html (problem with overflow and size).

    2. Create your own RTF component, I have not seen an RTF Renderer Component and I don't think there are any open tracker for this feature request in the JasperSoft Community

    3. Parse the RTF in java and use dynamic jasper to generate your report (or subreport relative to the RTF)

    When generating pdf, if font extension is not provided , iText will use (quoting @Bruno Lowagie) "its best effort" to render your font, this often is not enough. Consider adding font-extension to your project

    Check list for rendering font in pdf using jasper report

    How to add font extensions using iReport or JasperSoft Studio

    Note: If you are using the HTML Renderer Component this will not be needed since it is rendering an image.