I've made it work well. thanks.
There are many stream methods.You can use stream method on SVGGraphics2D that takes an Element parameter and pass your doc's document element. Just like this,
generator.stream(doc.getDocumentElement(),out);
//not this one generator.stream(out, true);
More details,
after you used the getRoot method, the 'content' of the SVGGraphics2D
has been moved over to your doc's document element and is no longer
contained in the SVGGraphics2D internal DOM structures.
has been moved over to your doc's document element and is no longer
contained in the SVGGraphics2D internal DOM structures.
ref: http://mail-archives.apache.org/mod_mbox/xmlgraphics-batik-users/200303.mbox/[EMAIL PROTECTED]
On 2/9/06, Alex Chew <[EMAIL PROTECTED]> wrote:
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 want i want.please show me the right way, thanks.code fragments://create document from existing svg fileString 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 the generator to the existing svg file
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();
--
借鉴/思考/执行/检验/推广
