The new CDK-JChemPaint code has been refactored such that the original code for the core functionality is now independent from the drawing toolkit. And we have two well-developed implementations, one for Swing/AWT (used by the JChemPaint applet), and one for SWT (used by Bioclipse). And there is one that generates SVG too, written by Gileain as a proof of principle.
The code is almost identical to the code for rendering molecules as PNG. We just swap the AWTDrawVisitor for the SVGGenerator:
-renderer.paint(triazole, new AWTDrawVisitor(g2)); +svgGenerator = new SVGGenerator(); +renderer.paint(triazole, svgGenerator);
Additionally, we need to change how we output the results. The below code generate the SVG and the matching HTML snippet:
new File("triazole.svg").append(svgGenerator.getResult()) file = new PrintWriter(new FileWriter(new File("triazole.html"))) file.println("<html>"); file.println("<body>"); file.print("<embed width=\"100\" height=\"100\" src=\"triazole.svg\" />"); file.println("</body>"); file.println("<html>"); file.close()
The result looks like: