SVG Converter – Convert SVG in Java

SVG is Scalable Vector Graphics. This is a vector image format for creating graphics and images that can be scaled up or down without losing quality. SVG images are created using XML code that describes the shapes, paths, lines, and colors that make up the image.

One of the main features of Aspose.HTML is its conversion capability. Aspose.HTML for Java provides easy access to conversion methods through its Converter class, which is a shared facade for most often conversion scenarios and offers a wide range of SVG conversions to popular formats like PDF, XPS, JPG, PNG, BMP, TIFF, and GIF.

How to Convert SVG in Java

The articles in the “SVG Converter” chapter give information on the list of supported SVG conversions and how to perform them using the Converter class.

To convert SVG, you should take a few steps:

  1. Install Aspose.HTML for Java library to convert SVG.
  2. Initialize a new instance of the SVGDocument class using one of SVGDocument() constructors.
  3. Create a Save Options object that specifies the desired output format and conversion options.
  4. Call one of the convertSVG() methods and pass the necessary parameters to it.

Please take a look over the following Java code snippet that shows the SVG to PNG conversion using the convertSVG(document, options, savePath) method.

 1	// Prepare a path to a source SVG file
 2    String documentPath = Path.combine(getDataDir(), "gradient.svg");
 3
 4    // Prepare a path for converted file saving 
 5    String savePath = Path.combine(getOutputDir(), "gradient-options.png");
 6
 7    // Initialize an SVG document from the file
 8    SVGDocument document = new SVGDocument(documentPath);
 9    try {
10        // Initialize an instance of ImageSaveOptions 
11        ImageSaveOptions options = new ImageSaveOptions();
12
13        // Convert SVG to PNG
14        com.aspose.html.converters.Converter.convertSVG(document, options, savePath);
15    }
16    finally {
17        if (document != null)
18            document.dispose();
19    }

Aspose.HTML offers a free online SVG Converter for converting SVG files to various popular formats. You can easily convert SVG to PDF, SVG to XPS, SVG to PNG, SVG to JPG, etc. Select the file and the format to convert, and you’re done. It’s fast and completely free!

You can download the complete Java examples and data files from GitHub.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.