You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Alex Chew <ch...@gmail.com> on 2006/03/06 04:37:09 UTC

how can i manipulate an existing svg file?

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