Hi,
  I want to modify an existing SVG file use SVGGraphics2D, but i cannot get anything in output file. I have read several similar subjects and followed the tips, but I still cannot get what i want.
 
please show me the right way, thanks.
 
code fragments:  
 
   //create document from existing svg file
   String parser = XMLResourceDescriptor.getXMLParserClassName();
   SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
   String filename = "D:\\test\\old.svg";
   File file = new File(filename);
   String uri=file.toURI().toString();
   Document doc = f.createDocument(uri);

   //manipulate
   SVGGraphics2D generator = new SVGGraphics2D(doc);
   Shape circle = new Ellipse2D.Double(0,0,50,50);
   generator.setPaint(Color.red);
   generator.fill(circle);
   generator.draw (circle);
   generator.setPaint(Color.CYAN);
   generator.drawString("Dance on SVG",60,60);

   //append objects in existing svg to Generator
   generator.getRoot(doc.getDocumentElement());
      
    //output as new file
   OutputStream os = new FileOutputStream("D:\\test\\new.svg");
   Writer out = new OutputStreamWriter(os, "UTF-8");
   generator.stream(out, true);
   os.close();
   out.close();

Reply via email to