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

Export to image


mackensen

Recommended Posts

Hello,

Is it possible to export a report as image stream ? I mean (pls see the code) from the JasperPrint to PNG or JPG but not to a saved image to harddisk, just as a stream. Now the export to pdf stream is ok.

The final goal is to have the report as a preview (like a tooltip) at mouseover event. So it has to be generated on the fly and displayed in a div or something, without saving the image.

Thankx,
Mackensen

Code:


Post Edited by mackensen at 02/27/2010 21:43
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

After reading another post I found this solution...maybe somebody needs it (my report has only one page so indexPage=0):

Code:
out = response.getOutputStream();                                 if (printType==0)  //if pdf stream  {                                                                          JasperExportManager.exportReportToPdfStream(jasperPrint, out);  } else {         // if jpeg image stream                int pageIndex = 0;                                                                                BufferedImage pageImage = new BufferedImage(jasperPrint.getPageWidth() + 1, jasperPrint.getPageHeight() + 1, BufferedImage.TYPE_INT_RGB);                                                                                JRGraphics2DExporter exporter = new JRGraphics2DExporter();                                                                                exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);                                                                                exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, pageImage.getGraphics());                                                                                exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));                                                                                exporter.exportReport();                                                                                ImageIO.write(pageImage, "jpeg", out);                                                                            }                                                                                out.close();
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...