mnshah9 Posted May 21, 2007 Share Posted May 21, 2007 Hi All I want to export report to any image format, My report is PAI Chart or any other chart i want to export that as image. Is it possible though JasperReport? if yes how i can implement it I tried it with JRGraphics2DExporter but it won't wrok. Can u pls help me. ThanksMaulik Link to comment Share on other sites More sharing options...
clarisys Posted May 22, 2007 Share Posted May 22, 2007 Here's an incomplete part of code I use in our application:Code: zoom = (float)1.6; logger.info("Rendering images (format "+new String(format)+"«») zoom: "+new Float(zoom).toString()); /* To get a correct by OS image Writer */ Iterator writers = ImageIO.getImageWritersByFormatName(new String(format)); ImageWriter writer = (ImageWriter)writers.next(); JasperPrintManager printManager = new JasperPrintManager(); BufferedImage[] rendered_images = new BufferedImage[(jasperPrint.getPages().size())]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); output = new byte[(jasperPrint.getPages().size())][]; for(int i = 0; i < jasperPrint.getPages().size(); i++) { try { rendered_images = (BufferedImage)printManager.printPageToImage(jasperPrint, i, zoom); } catch (JRException e) { String message = "Unable to export report to pdf."; logger.error(message, e); throw new JasperFillingException(message); } writer.setOutput(new MemoryCacheImageOutputStream(baos)); try { writer.write(new IIOImage(rendered_images, null, null)); } catch (IOException e) { String message = "Unable to write image to the given output stream..."; logger.error(message, e); throw new JasperServerException(message); } output = baos.toByteArray(); baos.reset(); writer.reset(); } logger.info("Rendered Images: "+ jasperPrint.getPages().size()); Enjoy, Link to comment Share on other sites More sharing options...
antuansoft Posted May 12, 2014 Share Posted May 12, 2014 Yes!! last answer works!!!!! and you can scale the image without loss of resolution and quality. I used JRGraphics2DExporter, but it doesn work using the zoom options, but using JasperPrintManager it works!!!!!!I have scaled the image to 1.6Here is my code based on last post but updated to the new Jasperreports versions (5.5.0 in my case) JasperPrint is the compiled jrxml with data filled into the report.....JasperReport jasperReport = compileReport("myReport.jrxml");parameters.put("title", "MyReport");.....Fill Data........print = JasperFillManager.fillReport(jasperReport, parameters, new JRBeanCollectionDataSource(data));[/code]FilePath is the destination where the image report will be written.private void extractPrintImage (String filePath, JasperPrint print){ File file = new File(filePath); OutputStream ouputStream= null; try{ ouputStream= new FileOutputStream(file); DefaultJasperReportsContext.getInstance(); JasperPrintManager printManager = JasperPrintManager.getInstance(DefaultJasperReportsContext.getInstance()); BufferedImage rendered_image = null; rendered_image = (BufferedImage)printManager.printPageToImage(print, 0,1.6f); ImageIO.write(rendered_image, "png", ouputStream); }catch(Exception e){ e.printStackTrace(); } }[/code] 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