Hello Thomas,
Thank you for your reply.
In my code, I actually declare 'SVGGraphics2D' object once (I either use the first one or the next one), but I forgot to comment one out when I pasted the code here.
I do not use any swing components to display the graph. I use JGraph ,which is an open source library that produces a graph of nodes and edges.
The funny thing is that if I use SVGGraphics2D svgGenerator = new SVGGraphics2D(document);, I get an SVG file that is big, but totally blank when I double click on it. There is also no scrolling capability.
However, if I use
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
ImageHandler ihandler = new ImageHandlerPNGEncoder( "D:\\", null);
ImageHandler ihandler = new ImageHandlerPNGEncoder( "D:\\", null);
ctx.setImageHandler(ihandler);
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
I acutally get a smaller SVG file which has a part of my graph in it (a few nodes), and many other temp files which has the other parts of my graph. There is also no scrolling capabilities in the SVG file.
Do you know what the problem is?
Thanks,
Rana
Thomas DeWeese <[EMAIL PROTECTED]> wrote:
Hi Rana,
Your code mostly looks ok, a few things looked a little
odd to me however.
First you declare 'SVGGraphics2D svgGenerator' twice!
so I might guess that you stream the first one and not the second.
Also you flush 'fos', but not 'out', you should flush 'out', then
flush 'fos' (then close fos). You might also want to look at what
it actually outputs - for example it might embed an image which would
be written to D: (but it might not be able to find it). For
Swing components you might want to use 'SwingSVGPrettyPrint' because
it will try to ensure that you don't just get Swing's double buffer.
Rana Khartabil wrote:
> 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!