简体   繁体   中英

Image doesn't load in JasperReport template for email

I´m having a problem using a JasperReport template to generate content for an email. I need the content to be inside a bordered content and to have an image像这样 But after i generate the template loaded with content it doesnt look like this in gmail or zimbra mail: 这是结果 As you can see the result doesn't look like the preview in JasperSoft Studio.

I want to know if there is a way to make sure that the image loads correctly and that the border contains the rest of the template

The jasper chunk for the image:

<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>

The java code for the template generation:

    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);
        }
    }

One thing that you can do is to set the isUseBackgroundImageToAlign export flag to false. As in

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

You can also set the flag via the net.sf.jasperreports.export.html.use.background.image.to.align configuration property.

Note however that this would probably result in the image no longer being aligned according to the scaleImage, hAlign and vAlign attributes, so you would need to set the JRXML image element dimension to the size that you want the image to have.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM