[英]Image doesn't load in JasperReport template for email
我在使用 JasperReport 模板為 email 生成內容時遇到問題。 我需要內容在有邊框的內容內並有圖像 但是在我生成加載了內容的模板后,它在 gmail 或 zimbra 郵件中看起來不像這樣:
如您所見,結果看起來不像 JasperSoft Studio 中的預覽。
我想知道是否有辦法確保圖像加載正確並且邊框包含模板的 rest
圖像的碧玉塊:
<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 圖像元素尺寸設置為您希望圖像具有的大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.