Fernando Bravo Diaz
Fernando Bravo Diaz

Reputation: 579

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 like this But after i generate the template loaded with content it doesnt look like this in gmail or zimbra mail: This is the result 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);
        }
    }

Upvotes: 0

Views: 323

Answers (1)

dada67
dada67

Reputation: 5093

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.

Upvotes: 0

Related Questions