DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
SVGDocument document = (SVGDocument) impl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator.
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
try{
disableDoubleBuffering(componentToExport);
componentToExport.paint(svgGenerator);
enableDoubleBuffering(componentToExport);
// SwingSVGPrettyPrint.print(componentToExport, svgGenerator);
// Populate the document root with the generated SVG content.
// Element root = document.getDocumentElement();
// svgGenerator.getRoot(root);
// JSVGCanvas canvas = new JSVGCanvas();
// canvas.setPreferredSize(new Dimension(800,600));
// JFrame f = new JFrame();
// f.getContentPane().setLayout(new BorderLayout());
// f.getContentPane().add("Center", canvas);
// canvas.setSVGDocument(document);
// f.pack();
// f.setVisible(true);
// Finally, stream out SVG to the standard output using
// UTF-8 encoding.
boolean useCSS = false; // we want to use CSS style attributes
Writer out = new OutputStreamWriter(fao, "UTF-8");
svgGenerator.stream(out, useCSS);
out.flush();
out.close();
}catch(Exception e){
throw e;
}finally{
svgGenerator.dispose();
svgGenerator = null;
}
}