Jump to content
Changes to the Jaspersoft community edition download ×
  • Exporting to SVG format


    djohnson53
    • Version: v5.1, v5.0, v4.8, v4.7, v4.6, v4.5 Product: JasperReports® Library

    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);


    User Feedback

    Recommended Comments

    exporter.setParameter is deprecated. can some one please update the above code to work with exporter.setExporterInput and exporter.setExporterOutput. thanks in advance

     

    Link to comment
    Share on other sites



    Guest
    This is now closed for further comments

×
×
  • Create New...