Hello, I am trying to save a jgraph
object as an SVG file and I’m having problems with it. I spent so much
time on it and so if someone encountered a similar problem or knows a solution,
I would greatly appreciate it. Basically, this method attempts to save the jgraph as SVG. The file is produced, but 1) it’s blank white and 2) there are no scrolling
capabilities. public void saveGraphAsSVG(JGraph graph) {
try {
/* Create file output stream. */
FileOutputStream fos
= new FileOutputStream(new
File("D:\\final.svg"));
/* Created writer with UTF-8 encoding. */
Writer out = new OutputStreamWriter(fos, "UTF-8");
/* Get a DOMImplementation. */
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
/* Create an instance of Document. */
Document document = domImpl.createDocument(null, "svg", null);
/* Create an instance of the SVG
Generator. */
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
SVGGeneratorContext ctx
= SVGGeneratorContext.createDefault(
document);
ImageHandler ihandler = new ImageHandlerPNGEncoder(
"D:\\", null);
ctx.setImageHandler(ihandler);
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
svgGenerator.setSVGCanvasSize(new Dimension(2000, 2000));
graph.paint(svgGenerator);
/* Use CSS style attribute. */
boolean useCSS = true;
/* Finally, stream out SVG to the writer. */
svgGenerator.stream(out, useCSS);
/* Close the file output stream. */
fos.flush();
fos.close();
}
catch (IOException e)
{
e.printStackTrace();
} } } Thanks, Rana |
- Re: Saving a JGraph object as SVG File Rana Khartabil
- Re: Saving a JGraph object as SVG File Thomas DeWeese
- Re: Saving a JGraph object as SVG File Rana Khartabil
- Re: Saving a JGraph object as SVG File Thomas DeWeese