You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by vbrown <vb...@id-bs.com> on 2006/10/24 11:42:17 UTC
Can't add height/width attribs to
I am trying to add the height and width attributes to the <svg> tag in my svg
document that I am generating from SVG2DGraphics but am not having much
success, here is the code I am trying:
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
Document document = domImpl.createDocument(null, "svg", null);
// get the root element (the svg element)
Element svgRoot = document.getDocumentElement();
// set the width and height attribute on the svg root element
svgRoot.setAttributeNS(null, "width", "400");
svgRoot.setAttributeNS(null, "height", "450");
//Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
BufferedImage image = ImageIO.read(new File("C:/simple circle.jpg"));
boolean result = svgGenerator.drawImage(image, 0, 0, null);
Writer out = new OutputStreamWriter(new FileOutputStream("C:/testing1.svg"),
"UTF-8");
svgGenerator.stream(out, true);
out.close();
I also tried getting the root from the svgGenerator object:
Element root = svgGenerator.getRoot();
root.setAttributeNS(null, "width", "400");
root.setAttributeNS(null, "height", "450");
And this didn't work either.
Any help in setting these attributes would be greatly appreciated. The Glips
editor won't read an svg file without these attributes set so I do need
them.
Thanks.
Victoria.
--
View this message in context: http://www.nabble.com/Can%27t-add-height-width-attribs-to-%3Csvg%3E-tag-when-using-SVG2DGraphics-tf2500244.html#a6969860
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Can't add height/width attribs to
Posted by vbrown <vb...@id-bs.com>.
I will answer my own question as I have worked out the solution.
if you set the size of the SVGCanvas it will add height and width attributes
to the <svg> tag.
svgGenerator.setSVGCanvasSize(new Dimension(image.getWidth() + 2,
image.getHeight() + 2));
--
View this message in context: http://www.nabble.com/Can%27t-add-height-width-attribs-to-%3Csvg%3E-tag-when-using-SVG2DGraphics-tf2500244.html#a7090794
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org