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 harvinder singh <ha...@hotmail.com> on 2008/02/22 14:11:07 UTC
Generating SVg from Graphics2D
Hello everyone,
I am developing
an application that generates Graphics2D visualisation of a network
(JUNG), I would like to convert the Graphics2D output of the current
visualization to and SVG document. However I am unabke to find
anything, I have Batik generating SVG from the sample provided on the
Batik website but how shouold I make it to generate an SVG of my
generated graphics (how should i forward the graphics to Batik) to make
it write an SVG output.
Please help!!!
Harvinder Singh
_________________________________________________________________
Free games, great prizes - get gaming at Gamesbox.
http://www.searchgamesbox.com
Re: Generating SVg from Graphics2D
Posted by Keywan Najafi Tonekaboni <li...@prometoys.net>.
Hi,
it seems nobody answers, so I will point you to my "dirty" code. I am a
student and not well experienced programmer, but maybe it is helpful
anyway.
I use this method:
private String generateSVG() throws
TransformerFactoryConfigurationError, TransformerException {
String result ="";
Transformer transformer;
transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// initialize StreamResult with File object to save to file
StreamResult streamResult = new StreamResult(new
StringWriter());
DOMSource source = new DOMSource(model.getSVGDoc());
transformer.transform(source, streamResult);
result = streamResult.getWriter().toString();
return result;
}
I use the String, which is returned with another method, to write it to
the disk:
private void saveFile(File saveFile, String xmlData) throws IOException
{
// File saveFile = new File(filename);
if(!saveFile.exists()){
// System.out.printf("Create new File %s. \n", filename);
saveFile.createNewFile();
FileWriter fw = new FileWriter(saveFile);
fw.write(xmlData);
fw.close();
} else {
System.out.printf("ERROR: File %s already exist. Did nothing. \n",
saveFile.toURI().toString());
}
}
I attached you the complete file. Hope this help you.
Regards,
Keywan
Am Freitag, den 22.02.2008, 13:11 +0000 schrieb harvinder singh:
> Hello everyone,
>
> I am developing an application that generates Graphics2D visualisation
> of a network (JUNG), I would like to convert the Graphics2D output of
> the current visualization to and SVG document. However I am unabke to
> find anything, I have Batik generating SVG from the sample provided on
> the Batik website but how shouold I make it to generate an SVG of my
> generated graphics (how should i forward the graphics to Batik) to
> make it write an SVG output.
>
> Please help!!!
>
> Harvinder Singh
>
>
>
> ______________________________________________________________________
> She said what? About who? Shameful celebrity quotes on Search Star!
--
Keywan Najafi Tonekaboni
http://www.prometoys.net
people@world:/# apt-get --purge remove dominion
After unpacking world will be freed.
You are about to do something potentially beneficial
To continue type in the phrase 'Yes, do as We say!'