Hello, I tried to include a viewbox-attribute when exporting a Graphics2D to SVG using batik.
I found some hints in the archive when searching 'viewbox' http://koala.ilog.fr/batik/mlists/batik-users/archives/msg01038.html http://koala.ilog.fr/batik/mlists/batik-users/archives/msg01040.html http://koala.ilog.fr/batik/mlists/batik-users/archives/msg01041.html http://koala.ilog.fr/batik/mlists/batik-users/archives/msg01043.html http://www.mail-archive.com/[EMAIL PROTECTED]/msg05387.html http://www.mail-archive.com/[EMAIL PROTECTED]/msg05389.html but they did not help me that much further..... I tried to include a viewbox via the batik-examples as given on the website (and as suggested in above links), using the given StyleSheetStyleHandler: -----begin copy public void createSVG( DrawingCanvas comp2SVG, File file) throws Exception { setCanvas(comp2SVG); //exception will be trhown by code below, has to be caught by user BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file)); // Get a DOMImplementation DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); // Create an instance of org.w3c.dom.Document // String svgNS = SVGSyntax.SVG_NAMESPACE_URI;//"http://www.w3.org/2000/svg";//SVGDOMImplementation.SVG_NAMESPACE_URI; Document document = domImpl.createDocument(null, "svg", null); // set context (i.e parameters) of the document SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document); CDATASection styleSheet = document.createCDATASection(""); ctx.setStyleHandler(new StyleSheetStyleHandler(styleSheet)); /** According to [EMAIL PROTECTED] do setPrecision(int precision) * to bypass the otherwise occurring java.lang.NullPointerException * at org.apache.batik.svggen.SVGGeneratorContext.doubleString(SVGGeneratorContext.java:420) * due to "a bug in doubleString where we did not initialize the DecimalFormat object". **/ ctx.setPrecision(3); // 3 is SVG-default as mentioned in SVGGeneratorContext.java. //something to set size of xml-document: ctx.setComment("Generated by The Visual Language with Batik SVG Generator"); // Create an instance of the SVG Generator with context and document SVGGraphics2D svg2d = new SVGGraphics2D(ctx, false); // add a style sheet to the definition section Element root = svg2d.getRoot(); Element defs = root.getElementById(SVGSyntax.ID_PREFIX_GENERIC_DEFS); Element style = document.createElementNS(SVGSyntax.SVG_NAMESPACE_URI,SVGSyntax.SVG_STYLE_TAG); style.setAttributeNS(null, SVGSyntax.SVG_TYPE_ATTRIBUTE, "text/css"); style.setAttributeNS(null, "viewBox", "0, 0, 600, 400" ); style.appendChild(styleSheet); defs.appendChild(style); // Finally, stream out SVG to the standard output using UTF-8 // character to byte encoding boolean useCSS = true; // we want to use CSS style attribute Writer outWriter = new OutputStreamWriter(out, "UTF-8"); // Ask the canvas to render into the SVG Graphics2D implementation //if(canvas==null) return; //would never happen because of setCanvas(); canvas.paintSVG(svg2d); canvas.repaint(); svg2d.stream(outWriter, useCSS); out.close(); } ---- end class But the compiler (in JDK 1.5) doesn't accept: root.getElementById(SVGSyntax.ID_PREFIX_GENERIC_DEFS); (the method belongs to Document, not Element...) How can I proceed ...? rob --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]