tqmsserver11 Posted April 23, 2014 Share Posted April 23, 2014 I sent the jasper report html file via email body with images but the images not showing. The image url look like this in gmail. Can anyone help me?https://ci6.googleusercontent.com/proxy/_m2t3F97VViYmw6ld0_IK_NoOKRCmr9IJ7azriGdHDkMX8S7SrJpXEr4XX_yj5SiV6fr_m5tB2GfcRo=s0-d-e1-ft#http://hibernate.html_files/img_0_0_0 Link to comment Share on other sites More sharing options...
nelson.alves Posted October 17, 2014 Share Posted October 17, 2014 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 regardsNelson Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now