Convert SVG to PNG in Java

Convert SVG files to PNG images using Aspose.Slides for Java without Microsoft PowerPoint.

Convert SVG to PNG in Java

Aspose.Slides for Java is a presentation processing API that can place an SVG file on a slide and render the slide as a PNG image.

You can load an SVG file as an ISvgImage, add it to a picture frame, and save the rendered slide image with ImageFormat.Png.

Convert SVG to PNG using Java

To convert SVG to PNG, add the source file to a Presentation and render the slide with getImage.

Java code for converting SVG into PNG

Presentation presentation = new Presentation();
try {
    String svgContent = new String(Files.readAllBytes(Paths.get("image.svg")));
    ISvgImage svgImage = new SvgImage(svgContent);
    IPPImage presentationImage = presentation.getImages().addImage(svgImage);

    ISlide slide = presentation.getSlides().get_Item(0);
    slide.getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0, presentationImage.getWidth(), presentationImage.getHeight(), presentationImage);

    IImage slideImage = slide.getImage(1f, 1f);
    try {
        slideImage.save("image.png", ImageFormat.Png);
    } finally {
        slideImage.dispose();
    }
} finally {
    presentation.dispose();
}

How to convert SVG to PNG using Aspose.Slides for Java API

These are the steps to convert SVG to PNG in Java.

  1. Install Aspose.Slides for Java .

  2. Add a library reference to your Java project.

  3. Load the source SVG file as an ISvgImage.

  4. Render the slide as a PNG image with getImage and ImageFormat.Png.

Free Online Converter

Convert presentations and slides online.

Convert SVG To Other Supported Formats

You can also convert SVG files and save them to other file formats.