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

Export report as an image


lelo.endrik
Go to solution Solved by lelo.endrik,

Recommended Posts

Greetings experts,

I am new to the jasper world, so my question might be quite simple. I wish to generate a report from my java application. It work fine when it comes to pdf and excel formats, but i want to try to export it as an image (such as jpg, png the extension is not important). Is there any class like JPdfExporter or any other easy way to achieve this? 

During my researches, i've came across JRGraphics2DExporter, but i didn't understand how it works, and if this is the right choice of what i'm trying to accomplish. I would like an example of it's usage.

Thank you in advance!

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

  • 1 month later...
  • Solution

A bit late in replying, but i thought this solution might be useful to someone else. I've managed to get JRGraphics2DExporter  to work, and it doesn generate a correct .png image.

[/code]
            JRGraphics2DExporter exporter = new JRGraphics2DExporter();
            BufferedImage bufferedImage = new BufferedImage(595, 860, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = (Graphics2D)bufferedImage.getGraphics();
            exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, g);
            exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, Float.valueOf(1));
            exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
            PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
            attrs.add(new PrinterResolution(500, 440, ResolutionSyntax.DPI));
            exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, attrs);
            exporter.exportReport();
            g.dispose();
 
            ImageIO.write(bufferedImage, "PNG", out);

      


 

 

Link to comment
Share on other sites

  • 7 years later...

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...