private static String getMolSvg(IAtomContainer cdkmol, int width, int height) throws UnsupportedEncodingException, SVGGraphics2DIOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
List<IGenerator> generators = new ArrayList<IGenerator>();
generators.add(new BasicBondGenerator());
generators.add(new BasicAtomGenerator());
Renderer renderer = new Renderer(generators,new AWTFontManager(), false);
RendererModel r2dm = renderer.getRenderer2DModel();
r2dm.setDrawNumbers(false);
r2dm.setBackColor(Color.LIGHT_GRAY);
r2dm.setIsCompact(true);
r2dm.setShowImplicitHydrogens(false);
r2dm.setShowEndCarbons(false);
int number=((int)Math.sqrt(cdkmol.getAtomCount()))+1;
int moleculewidth = number*100;
int moleculeheight = number*100;
if(width>-1){
moleculewidth=width;
moleculeheight=height;
}
if(moleculeheight<200 || moleculewidth<200){
r2dm.setIsCompact(true);
r2dm.setBondDistance(3);
}
Rectangle drawArea = new Rectangle(moleculewidth, moleculeheight);
renderer.setup(cdkmol, drawArea);
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
Document document = domImpl.createDocument(null, "svg", null);
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
svgGenerator.setBackground(Color.LIGHT_GRAY);
svgGenerator.setColor(Color.LIGHT_GRAY);
svgGenerator.fill(new Rectangle(0, 0, moleculewidth, moleculeheight));
renderer.paintMolecule(cdkmol, new AWTDrawVisitor(svgGenerator), drawArea, false);
boolean useCSS = false;
baos = new ByteArrayOutputStream();
Writer outwriter = new OutputStreamWriter(baos, "UTF-8");
StringBuffer sb = new StringBuffer();
svgGenerator.stream(outwriter, useCSS);