We have HTML from database, and we would like to create a Word report with this HTML. This HTML comes from users, and may contain only formatted text (bold, italic...), or text + embedded image encoded in base64 way.
Example:
<b>My photo :</b>
<img src="data:image/png;base64,iVBORw0K... " />
We know that with textField
, markup="html"
, it does not work with img
html tags. With Jasper Studio 6.3.1, we tried with <hc:html/>
, it works with image on the hard drive, but it won't work with embedded image, saying there are syntax errors on the base64 encryption.
jrxml file :
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="StylesReport" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" uuid="53f914b8-f951-4433-971d-6b1819430c56">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<property name="net.sf.jasperreports.export.html.embed.image" value="true"/>
<import value="org.apache.commons.codec.binar.*"/>
<title>
<band height="742">
<textField hyperlinkType="Reference" hyperlinkTarget="Blank">
<reportElement x="0" y="30" width="515" height="30" uuid="c2015c9b-9130-4f39-a09e-c341c91d3794"/>
<textElement textAlignment="Center">
<font size="18"/>
</textElement>
<textFieldExpression><![CDATA["HTML Element Report"]]></textFieldExpression>
</textField>
<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="RetainShape" horizontalAlign="Left" verticalAlign="Middle">
<hc:htmlContentExpression><![CDATA["<p style='background-color:yellow;font-family:verdana;font-size:50px;'>Hi, I am through HTML CODE using HTML Component</p><br><br><img src='data:image/gif;base64,/9j/dkjdkdkdkddk(INSERTIMAGEHEREITSTOOLONG!!!)' alt='Japser Architecture' height='1000' width='1800'>"]]></hc:htmlContentExpression>
</hc:html>
</componentElement>
</band>
</title>
</jasperReport>
Is it possible to do this with Jasper ? We wouldn't like to parse the HTML from database to do tons of things with, we really would like the HTML written as-is on the report.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…