Created
January 15, 2026 17:58
-
-
Save aspose-com-gists/728b26cade750c9f80dddf52fb373522 to your computer and use it in GitHub Desktop.
Generate an SVG Image from a Slide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.aspose.slides.*; | |
| import java.io.FileOutputStream; | |
| public class GenerateSvgFromSlides { | |
| public static void main(String[] args) { | |
| // Validate arguments | |
| if (args.length < 2) { | |
| System.out.println("Usage: java GenerateSvgFromSlides <input.pptx> <outputFolder>"); | |
| return; | |
| } | |
| String inputPath = args[0]; | |
| String outputFolder = args[1]; | |
| if (!outputFolder.endsWith("/") && !outputFolder.endsWith("\\")) { | |
| outputFolder += System.getProperty("file.separator"); | |
| } | |
| try { | |
| // Load presentation | |
| Presentation pres = new Presentation(inputPath); | |
| // Set up SVG export options | |
| SvgOptions svgOptions = new SvgOptions(); | |
| svgOptions.setCompressOutput(true); | |
| svgOptions.setExportEmbeddedImages(true); | |
| // Optional: custom shape IDs | |
| svgOptions.setShapeIdGenerator(new ISvgShapeIdGenerator() { | |
| @Override | |
| public String generateId(IShape shape) { | |
| return "slide" + shape.getSlide().getSlideNumber() + "_shape" + shape.getShapeId(); | |
| } | |
| }); | |
| // Export each slide | |
| for (int i = 0; i < pres.getSlides().size(); i++) { | |
| ISlide slide = pres.getSlides().get_Item(i); | |
| String outPath = outputFolder + "slide_" + (i + 1) + ".svg"; | |
| try (FileOutputStream out = new FileOutputStream(outPath)) { | |
| slide.writeAsSvg(out, svgOptions); | |
| } | |
| System.out.println("Exported: " + outPath); | |
| } | |
| System.out.println("All slides have been successfully converted to SVG."); | |
| } catch (Exception e) { | |
| System.err.println("Error during conversion: " + e.getMessage()); | |
| e.printStackTrace(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment