SVG to JPG Conversion with the Java API

Aspose.HTML for Java converts SVG files, code, and URLs to JPG with Converter.convertSVG() . Load the source into SVGDocument, select ImageFormat.Jpeg in ImageSaveOptions, and provide the output path. The renderer processes vector geometry, text, CSS, and linked resources before creating the raster image.


Save SVG Artwork as a JPG Image

The example opens document.svg, selects JPEG output, and writes output.jpg. Try-with-resources releases the SVG document automatically.

Convert SVG to JPG in Java

import com.aspose.html.converters.Converter;
import com.aspose.html.dom.svg.SVGDocument;
import com.aspose.html.rendering.image.ImageFormat;
import com.aspose.html.saving.ImageSaveOptions;

// Load the SVG document
try (SVGDocument document = new SVGDocument("document.svg")) {
    // Select JPEG output
    ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Jpeg);

    // Convert SVG to JPG
    Converter.convertSVG(document, options, "output.jpg");
}

Preview SVG to JPG Conversion Online

Upload an SVG file or enter its URL to inspect the JPG result before implementing the conversion in Java.

SVG to JPG API Workflow

  1. Add Aspose.HTML for Java to the project.
  2. Load the source with SVGDocument .
  3. Create ImageSaveOptions with ImageFormat.Jpeg.
  4. Call Converter.convertSVG() with the document, options, and output path.

Adjust JPG Resolution and Background

ImageSaveOptions controls resolution, page dimensions, margins, background color, smoothing, CSS processing, and text rendering. JPG uses lossy compression and does not support transparency. Set a suitable background color for transparent SVG regions, or use SVG to PNG when transparency must be retained.

See Convert SVG to JPG in Java and the ImageSaveOptions API Reference .


Install Aspose.HTML for Java

Add Aspose.HTML for Java from the official Aspose repository. Replace ASPOSE_HTML_VERSION with an exact version from the Aspose.HTML for Java releases page, then reload or rebuild the project so the dependency is resolved.

Add the repository and dependency to the Maven project:

Maven – pom.xml

<repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <url>https://releases.aspose.com/java/repo/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-html</artifactId>
        <version>ASPOSE_HTML_VERSION</version>
    </dependency>
</dependencies>

Add the repository and dependency to the Gradle project:

Gradle – build.gradle

repositories {
    maven {
        url = uri('https://releases.aspose.com/java/repo/')
    }
}
dependencies {
    implementation 'com.aspose:aspose-html:ASPOSE_HTML_VERSION'
}

Use a JDK compatible with the selected release. For manual JAR installation, Kotlin DSL, updates, and dependency troubleshooting, see Install Aspose.HTML for Java .


SVG to JPG Conversion FAQ

1. What happens to transparent areas when SVG is converted to JPG?

JPG does not support transparency. Configure a background color in ImageSaveOptions so transparent SVG regions render against the intended fill.

2. Why can small SVG text look softer in JPG output?

SVG text is rasterized to pixels and JPG applies lossy compression. Increase the output resolution or choose PNG when sharp text edges are more important than file size.

3. Can Java convert inline SVG code directly to JPG?

Yes. Use a Converter.convertSVG() overload that accepts SVG markup, a base URI for relative resources, image save options, and the output path.

4. Can I convert SVG to JPG online for free?

Yes. Use the free online SVG to JPG converter for a manual conversion. Use Aspose.HTML for Java for application integration.

Related Java Conversions

Choose another SVG output or a related JPG workflow.