xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Baris YILMAZ <baris_...@yahoo.com>
Subject Newbie question
Date Sun, 11 Jun 2006 18:49:34 GMT

I am a newbie in Batik and try to generate a simple svg file as below. But somehow, my rectange
is not appended to my svg file. Can anyone tell me why?

Moreover, I am trying to find a tutorial on Batik. Except whose in the homepage I can't find
anything. The ones in the homepage, are very bad written and simple...

I'll appreciate your help..

public class SVGNeu {

    public static void main(String[] args) throws IOException {
        DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
        String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
        Document doc = impl.createDocument(svgNS, "svg", null);

//         get the root element (the svg element)
        Element svgRoot = doc.getDocumentElement();

//         set the width and height attribute on the root svg element
        svgRoot.setAttributeNS(null, "width", "400");
        svgRoot.setAttributeNS(null, "height", "450");

//         create the rectangle
        Element rectangle = doc.createElementNS(svgNS, "rect");
        rectangle.setAttributeNS(null, "x", "10");
        rectangle.setAttributeNS(null, "y", "20");
        rectangle.setAttributeNS(null, "width", "100");
        rectangle.setAttributeNS(null, "height", "50");
        rectangle.setAttributeNS(null, "style", "fill:red");

//         attach the rectangle to the svg root element
        SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(doc);
        ctx.setComment("Generated by FooApplication with Batik SVG Generator");
        SVGGraphics2D g2d = new SVGGraphics2D(ctx, false);
        // 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 out = new OutputStreamWriter(System.out, "UTF-8");
        g2d.stream(out, useCSS);

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
View raw message