Generating SVG image in Java

11,072

It depends what additional requirements you have. SVG files are XML files, so they are really just plain text files. You can create them with any of the standard IO methods. For example, this Java program satisfies your question:

public static void main(String[] args){
   System.out.println("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"100\" height=\"100%\">");
   System.out.println("<circle cx=\"50\" cy=\"50\" r=\"30\" fill=\"red\">");
   System.out.println("</svg>");
}

Perhaps you want to create and manipulate DOM objects, similar to how you do it in Javascript. If that is the case, then you may want to try the Apache Batik library. You should be able to find plenty of tutorials on how to use that, both here on SO, and elsewhere on the web.

Share:
11,072
Admin
Author by

Admin

Updated on June 15, 2022

Comments

  • Admin
    Admin about 2 years

    Although I have a very simple question I have not found any good answer anywhere.

    I would like to write a program (in Java) to create an SVG Image.

    For example I would like to create an SVG file which would contain red circle with some set radius.

    I would truly appreciate if someone could help me to find some tutorial for this kind of work. I spent a lot of time searching but I could not find anything. (Maybe I am using wrong keywords or something...)

    Thank you