Jump to content
We've recently updated our Privacy Statement, available here ×

How to sent the report html file via email body with images?


tqmsserver11

Recommended Posts

  • 5 months later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hello,

You can embed the images when you export to html. Example:

private static void exportToHTML(final JasperPrint jasperPrint, final OutputStream outputStream) throws JRException {

        final JRHtmlExporter exporter = new JRHtmlExporter();

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
        exporter.setImageHandler(new HtmlResourceHandler() {

            private final Map<String, byte[]> imageMap = new HashMap<>();

            @Override
            public void handleResource(final String id, final byte[] data) {

                //this method will be invoked by the jasper engine at filling time for each image and provide you a image key and the image content  

                this.imageMap.put(id, data);

            }

            @Override
            public String getResourcePath(final String id) {

               //this method will be invoked by the jasper engine in order to get a value for the image property 'src'. So we can provide here the image content using the earlier key.
                return "data:image/x-png;base64," + Base64.encodeBase64String(this.imageMap.get(id));
            }
        });

        exporter.exportReport();

    }

 

Best regards

Nelson

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...