Hi ,
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.
> 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.
void saveLayout()
{
System.out.println("yes");
try {
{
System.out.println("yes");
try {
/* Create file output stream. */
FileOutputStream fos = new FileOutputStream(new
File("D:\\test\\final1.png"));
/* 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, "png", null);
/* Create an instance of the SVG Generator. */
// SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(
document);
ImageHandler ihandler = new ImageHandlerPNGEncoder(
"D:\\test\\", null);
ctx.setImageHandler(ihandler);
//
//GenericImageHandler ihandler = new CachedImageHandlerBase64Encoder();
//ctx.setGenericImageHandler(ihandler);
//ctx.setGenericImageHandler(ihandler);
//
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
svgGenerator.setSVGCanvasSize(new Dimension(10000,1000));
// svgGenerator.setClip(0,0,10000, 10000);
//here newOne is Jgraph object
newOne.setSize(((JGraph) newOne).getPreferredSize());
newOne.paint(svgGenerator);
svgGenerator.setSVGCanvasSize(new Dimension(10000,1000));
// svgGenerator.setClip(0,0,10000, 10000);
//here newOne is Jgraph object
newOne.setSize(((JGraph) newOne).getPreferredSize());
newOne.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. */
out.flush();
fos.flush();
out.flush();
fos.flush();
fos.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
regrads
sudha
Do you Yahoo!?
Check out the new Yahoo! Front Page. www.yahoo.com