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:
- Install Aspose.HTML for Java library to convert SVG.
- Initialize a new instance of the SVGDocument class using one of SVGDocument() constructors.
- Create a Save Options object that specifies the desired output format and conversion options.
- 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 }
Popular SVG Conversions
- Convert SVG to PDF – Learn how to convert SVG to PDF using Java library.
- Convert SVG to XPS – Consider various SVG to XPS conversion scenarios in Java code.
- Convert SVG to PNG – Learn how to convert SVG to PNG with Aspose.HTML for Java, and you can easily use the Java code described here to convert SVG to JPG, BMP, GIF, TIFF.
- Convert SVG to JPG – Know how to convert SVG to JPG using the
convertSVG()
methods of the Converter class and how to apply ImageSaveOptions.
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.