O'Reilly logo

Java™ Drawing with Apache Batik: A Tutorial by Alexander Kolesnikov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Characters Positioning

There are so many things you can do with text in SVG. First of all, let’s put together all the code we will use. Here is the extract from the SVG Writer source code that creates the text element:

// Creating the <text> element
textElement = document.createElementNS(svgNS, "text");

// Setting the textual content
Text text = document.createTextNode(txt);
textElement.appendChild(text);

// Setting the attributes
textElement.setAttributeNS(null, "x", "30");
textElement.setAttributeNS(null, "y", "70");
textElement.setAttributeNS(null, "font-family",
    "Verdana, Arial, sans-serif");
textElement.setAttributeNS(null, "font-size", "40");
textElement.setAttributeNS(null, "fill", "slateblue");

The text element generated from the Text ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required