Languages
[Edit]
EN

Java - convert SVG file to PNG file

7 points
Created by:
Broncono
466

In this article, we would like to show how to convert SVG file to PNG file using Java.

By default Java ImageIO doesn't support SVG files. It is necessary to use some external implementation that is Apache™ Batik SVG Toolkit.

The article contains example project that let's to convert SVG files to PNG files.

 

Example project

Edit

The project was created as Mavan project and run using VS Code.

Project structure

Edit
Java project structure that contains logic to convert SVG files to PNG files.
Java project structure that contains logic to convert SVG files to PNG files.

 

Project files

Edit

Used SVG file is available here and should be saved under e.g. /path/to/input.svg (change it in Program.java file also).

 

src/main/java/com/example/Program.java file:

 

pom.xml file:

 

Project running (using command line)

Edit

Build project using:

Run project using:

 

See also

Edit
  1. Java - convert SVG file to JPG file

  2. Java - convert SVG string to BufferedImage

References

Edit
  1. Apache™ Batik SVG Toolkit
  2. Transcoder API - Apache Docs
  3. Batik Codec - Maven Repository
  4. Batik Transcoder - Maven Repository
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join