It is very easy to export a JasperReports generated document to SVG format, even though there is no specialized SVG exporter implementation available.
The help comes from the Batik library, which provides an implementation of the java.awt.Graphics2D abstract class. This in turn can be used in combination with the existing JRGraphics2DExporter to produce SVG content for a given page or a page range.
For exporting the first page of an in-memory JasperPrint document to SVG, the code should look like this:
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); Document document = domImpl.createDocument(null, "svg", null); SVGGraphics2D grx = new SVGGraphics2D(document); JRGraphics2DExporter exporter = new JRGraphics2DExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, grx); exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(0)); exporter.exportReport();\\ grx.stream(new FileWriter(new File("MyReport.svg")), true);
Log in or register to post comments
Comments
the above code does not work with newer version of jasper
exporter.setParameter is deprecated.
can some one please update the above code to work with exporter.setExporterInput and exporter.setExporterOutput.
thanks in advance
Log in or register to post comments