Export a report as an image

Map parameters = new HashMap();
JasperPrint jasperPrint =
JasperFillManager.fillReport(
(JasperReport) JRLoader.loadObject(new File("d:/injuryPresume.jasper")), parameters, new JREmptyDataSource());
JRGraphics2DExporter exporter = new JRGraphics2DExporter();

BufferedImage bufferedImage = new BufferedImage(jasperPrint.getPageWidth() * 4, jasperPrint.getPageHeight() * 4, BufferedImage.TYPE_INT_RGB);

Graphics2D g = (Graphics2D) bufferedImage.getGraphics();

exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, g);
exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, Float.valueOf(4));
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.exportReport();
g.dispose();

ImageIO.write(bufferedImage, "JPEG", new File("d:/aa.jpg"));

留言

這個網誌中的熱門文章

Disable ionic's sidemenu content drag to toggle menu

Multiple writable mappings exist for the field. Only one may be defined as writable, all others must be specified read-only.

java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser