SVG Converter in Java

Aspose.HTML for Java converts SVG to PDF, XPS, DOCX, JPG, PNG, BMP, GIF, and TIFF. Pass an SVG file, URL, inline SVG string, or SVGDocument to a suitable Converter.convertSVG() overload with the save options for the required output.

SVG, or Scalable Vector Graphics, is an XML-based format for two-dimensional graphics. Shapes, paths, text, colors, and transformations remain resolution-independent in the SVG source. Conversion is useful when the target workflow requires a fixed-layout document or a raster image instead of SVG markup.

How SVG Conversion Works

  1. Prepare the SVG source as a file, URL, inline string, or SVGDocument.
  2. Create the save options for the required output, such as PdfSaveOptions, XpsSaveOptions, DocSaveOptions, or ImageSaveOptions.
  3. Call a Converter.convertSVG() overload with the source, save options, and output path.

The following example writes a circle to document.svg, loads the file as an SVGDocument, and converts it to output.gif with ImageFormat.Gif.

 1// Convert SVG to GIF in Java
 2
 3// Prepare SVG code and save it to a file
 4String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
 5        "<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
 6        "</svg>\n";
 7try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.svg")) {
 8    fileWriter.write(code);
 9}
10
11// Initialize an SVG document from the SVG file
12SVGDocument document = new SVGDocument("document.svg");
13
14// Initialize ImageSaveOptions
15ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Gif);
16
17// Convert SVG to GIF
18Converter.convertSVG(document, options, "output.gif");

Download complete Java examples and data files from GitHub.

SVG Conversion Guides

Related SVG Workflows

Other Platforms

Try Online SVG Conversion

Use the free online SVG Converter for quick manual conversion to PDF, XPS, DOCX, or image formats without writing Java code. Use Aspose.HTML for Java when SVG conversion must run programmatically.