gpt4 book ai didi

java - 电子邮件的 JasperReport 模板中未加载图像

转载 作者:行者123 更新时间:2023-12-01 22:55:27 25 4
gpt4 key购买 nike

我在使用 JasperReport 模板生成电子邮件内容时遇到问题。我需要内容位于带边框的内容内并具有图像 like this但在我生成加载内容的模板后,它在 gmail 或 zimbra 邮件中看起来并不像这样: This is the result正如您所看到的,结果与 JasperSoft Studio 中的预览不同。

我想知道是否有办法确保图像正确加载并且边框包含模板的其余部分

图像的碧 Jade block :

<image scaleImage="RealSize" hAlign="Center" vAlign="Middle" isLazy="true">
<reportElement x="160" y="50" width="240" height="130" isRemoveLineWhenBlank="true" uuid="e72e685c-99f5-4dff-9174-2e25cab4a899"/>
<graphicElement fill="Solid"/>
<imageExpression><![CDATA["(https://domain/fe-standalone/files/resource/image.png)"]]></imageExpression>
</image>

模板生成的java代码:

    protected void exportToHTML(String jasperPath, ExportParams params, Connection connection, ByteArrayOutputStream baos) throws SQLException, JRException {
try {
Map<String, Object> parameters = new HashMap<>();
parameters.putAll(params.getParameters());
JasperPrint jasperPrint = fillReport(getClass().getResourceAsStream(jasperPath), parameters, connection);

SimpleHtmlExporterOutput oseo = new SimpleHtmlExporterOutput(baos);

HtmlExporter exporter = new HtmlExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(oseo);
exporter.setConfiguration(new SimpleHtmlExporterConfiguration());
exporter.exportReport();
connection.close();
} catch (JRException e) {
connection.close();
throw new JRException(e);
}
}

最佳答案

您可以做的一件事是将 isUseBackgroundImageToAlign 导出标志设置为 false。如

SimpleHtmlReportConfiguration configuration = new SimpleHtmlReportConfiguration();
configuration.setUseBackgroundImageToAlign(false);
exporter.setConfiguration(configuration);

您还可以通过 net.sf.jasperreports.export.html.use.background.image.to.align 设置标志配置属性。

但请注意,这可能会导致图像不再根据 scaleImage、hAlign 和 vAlign 属性进行对齐,因此您需要将 JRXML 图像元素尺寸设置为您希望图像具有的大小。

关于java - 电子邮件的 JasperReport 模板中未加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58441873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com