这是一个很好的挑战,问题是它不受支持,但并不意味着它无法完成.
html组件使用JEditorPane将html呈现为图像,并且“data:”没有默认的协议处理程序.
然而,这个优秀的answer到Joop Eggen显示了如何添加一个.
例
jrxml(htmlComponentBase64.jrxml)
Hi, I am through HTML CODE using HTML Component
![Japser Architecture](https://i-blog.csdnimg.cn/blog_migrate/0b3602e1ad0b3b0e612feac0c29f052b.gif)
java的
添加Joop Eggen的协议处理程序(记得将他归类,也许是一个不错的upvote)并执行这个java代码,在这种情况下导出为pdf
public class TestReport {
public static void main(String[] args) throws JRException {
Handler.install(); //Install Joop's protocol handler
//Compile report and fill, no datasource needed
JasperReport report = JasperCompileManager.compileReport("htmlComponentBase64.jrxml");
JasperPrint jasperPrint = JasperFillManager.fillReport(report, new HashMap());
//Export to pdf
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("pdf/htmlcomponentbase64.pdf"));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
exporter.setConfiguration(configuration);
exporter.exportReport();
}
}
享受结果
不是最好的报告,但显示图像
I have added a 07004 in jasper-reports community, to include a data protocol handler in future release