我们有来自数据库的HTML,我们想用这个HTML创建一个Word报告.此HTML来自用户,可能只包含格式化文本(粗体,斜体...),或以base64方式编码的文本+嵌入图像.
例:
<b>My photo :</b>
<img src="data:image/png;base64,iVBORw0K... " />
Run Code Online (Sandbox Code Playgroud)
我们知道,使用textField,markup="html"它不适用于imghtml标签.使用Jasper Studio 6.3.1,我们尝试使用<hc:html/>,它适用于硬盘驱动器上的图像,但它不适用于嵌入式图像,说base64加密有语法错误.
jrxml文件:
<?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" …Run Code Online (Sandbox Code Playgroud) 是否有任何API /解决方案可以从XML文件数据和定义生成PDF报告.例如,XML定义/数据可以是:
<pdf>
<paragraph font="Arial">Title of report</paragraph>
</pdf>
Run Code Online (Sandbox Code Playgroud)
将HTML转换为PDF也是一个很好的解决方案.
目前我们使用iText API编写Java代码.我希望外部化代码,以便非技术人员可以编辑和进行更改.