Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include Images and Tables in Textfields when exporting to PDF?

Is there a way to include images and tables in Textfields with markup=html, when exporting a PDF using JasperReports?

When I add a textfield with markup=html to my report, basic HTML support is provided out of the box, e.g.:

<textField>
    <reportElement .../>
    <textElement markup="html"/>
    <textFieldExpression><![CDATA["<html>some <b>bold</b> text</html>"]]></textFieldExpression>
</textField>

However, more complex HTML seems not to be supported. If I got that right, one would have to write a custom MarkupProcessor to transform the incoming HTML to jrxml and plug it into the JasperReports engine to handle more complex examples.

Since we use a CKEditor to handle the input, the list of used tags should be manageable. Secondly, we already use Jsoup to parse and cleanup HTML, which might be useful implementing the MarkupProcessor.

Is there an example I could build on? As I said, I'm mainly looking for image (img) and table (table, tr, td) support.

If not, is there an alternative to achieve this using JasperReports?

like image 301
Tim Büthe Avatar asked Feb 03 '15 16:02

Tim Büthe


1 Answers

It seems impossible indeed. What we do now instead is inserting images at predefined locations in the jrxml instead, and config limited functionality of ckeditor. Another option would be to extract the image urls from ckeditor and insert them at predefined locations in the jrxml, but we don't use that right now.

like image 124
Albert Hendriks Avatar answered Nov 01 '22 17:11

Albert Hendriks