SVG libraries for Java
Java has 3 well-maintained choices:
- Apache Batik is the complete SVG toolkit: an SVG DOM, a renderer, transcoders to PNG, JPEG and TIFF (and PDF with Apache FOP), a Swing viewer component and
SVGGraphics2Dto generate SVG from Java2D code. It’s large (several MB, many modules) and its rendering is slower, but it supports more of SVG 1.1 than anything else in Java, including scripting. - JSVG is a small, fast renderer that draws SVG on any
Graphics2D. IntelliJ IDEA, NetBeans and FlatLaf use it for icons. It uses much less memory than Batik and has no dependencies. Pick it to display or rasterize SVG. - JFreeSVG is a
Graphics2Dimplementation that writes SVG: draw with the normal Java2D API (or JFreeChart) and get an SVG string. It’s fast and has no dependencies, but is licensed GPL-3.0.
To generate SVG under a permissive license use Batik’s SVGGraphics2D; to render, use JSVG unless you need Batik’s DOM or scripting.
- Batik Apache Batik is the Java SVG toolkit. How to add it with Maven, convert SVG to PNG and JPEG with transcoders, read and modify the SVG DOM, get bounds.
- JFreeSVG JFreeSVG is a fast Java library that generates SVG from Graphics2D drawing code (GPL-3.0). How to add it, draw shapes and text, save SVG and SVGZ files.
- JSVG JSVG is a small, fast Java SVG renderer for Graphics2D, used by IntelliJ IDEA. How to add it, render SVG to a BufferedImage and PNG, scale it.