Render Presentation Slides as SVG Images in Python via Java
Overview
SVG is a scalable XML-based image format that works well for web publishing, slide viewers, accessibility workflows, and automated post-processing. Aspose.Slides exports each slide to a separate SVG file and lets you control how text, fonts, pictures, and SVG elements are written.
Use SVGOptions when the exported SVG must be compact, predictable across browsers, or ready for interactive use.
Export a Slide as SVG
Create a Presentation, select a slide, and write it to a stream with Slide.writeAsSvg. The examples require an existing presentation.pptx file. Each example starts the JVM if needed and closes its output streams. The following example exports every slide in a presentation as a separate SVG file.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation
from java.io import FileOutputStream
presentation = Presentation("presentation.pptx")
try:
for slide in presentation.getSlides():
output_file_name = f"slide-{slide.getSlideNumber()}.svg"
svg_stream = FileOutputStream(output_file_name)
try:
slide.writeAsSvg(svg_stream)
finally:
svg_stream.close()
finally:
presentation.dispose()
The filename uses Slide.getSlideNumber rather than the loop index. You can also export an individual shape with Shape.writeAsSvg when a slide viewer or web page needs only that shape.
Configure SVG Output
SVGOptions controls SVG rendering. For text frames, SVGOptions.setUseFrameSize includes the text frame in the rendering area, and SVGOptions.setUseFrameRotation determines whether the frame rotation is applied. Set SVGOptions.setDisableFontLigatures to True when text must be rendered without ligatures.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation, SVGOptions
from java.io import FileOutputStream
presentation = Presentation("presentation.pptx")
try:
svg_options = SVGOptions()
svg_options.setDisableFontLigatures(True)
svg_options.setUseFrameSize(True)
svg_options.setUseFrameRotation(False)
slide = presentation.getSlides().get_Item(0)
svg_stream = FileOutputStream("slide-with-custom-options.svg")
try:
slide.writeAsSvg(svg_stream, svg_options)
finally:
svg_stream.close()
finally:
presentation.dispose()
Control Line-End Cropping at Arrowheads
SVG 1.1 has no marker inset setting to specify where a line should stop beneath an arrowhead. By default, Aspose.Slides shortens the exported line so its stroke does not protrude through the marker. Call SVGOptions.setDisableLineEndCropping with True to draw the stroke all the way to the line’s original endpoint. This setting affects only the SVG output. The line keeps its position and length on the slide.
The example draws triangle and diamond arrowheads on lines 2 and 10 points wide. It exports the same slide twice, changing only the cropping option.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import FillType, LineArrowheadStyle, Presentation, ShapeType, SVGOptions
from java.awt import Color
from java.io import FileOutputStream
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
y = 40
for style in [LineArrowheadStyle.Triangle, LineArrowheadStyle.Diamond]:
for width in [2, 10]:
line = slide.getShapes().addAutoShape(ShapeType.Line, 40, y, 200, 0)
line_format = line.getLineFormat()
line_format.getFillFormat().setFillType(FillType.Solid)
line_format.getFillFormat().getSolidFillColor().setColor(Color(0, 0, 139))
line_format.setWidth(width)
line_format.setEndArrowheadStyle(style)
y += 50
svg_options = SVGOptions()
for disable_cropping, output_file_name in [(False, "cropped.svg"), (True, "uncropped.svg")]:
svg_options.setDisableLineEndCropping(disable_cropping)
svg_stream = FileOutputStream(output_file_name)
try:
slide.writeAsSvg(svg_stream, svg_options)
finally:
svg_stream.close()
finally:
presentation.dispose()
The comparison shows the triangular arrowhead on the 10-point line. With cropping enabled, the tip is sharp. With cropping disabled, the stroke protrudes through the sloping sides of the marker and leaves a flat end.

In the other lines from the example, the protruding stroke is less visible on the 2-point triangle. The filled diamond covers the end of the stroke at both widths.
Control Text and Fonts
When exporting slides to SVG, you can control whether text remains as text or is converted to vector graphics, and how external fonts are included or referenced. The following options help you balance visual consistency, text selection, and font dependencies in the exported SVG.
Vectorize All Text
Set SVGOptions.setVectorizeText to True to write all slide text as vector graphics. This eliminates font dependencies and makes the visual result more consistent across browsers, but the text is no longer selectable or searchable as SVG text.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation, SVGOptions
from java.io import FileOutputStream
presentation = Presentation("presentation.pptx")
try:
svg_options = SVGOptions()
svg_options.setVectorizeText(True)
slide = presentation.getSlides().get_Item(0)
svg_stream = FileOutputStream("slide-with-vectorized-text.svg")
try:
slide.writeAsSvg(svg_stream, svg_options)
finally:
svg_stream.close()
finally:
presentation.dispose()
Choose How External Fonts Are Handled
SVGOptions.setExternalFontsHandling uses a SvgExternalFontsHandling value for fonts that are loaded externally. Choose AddLinksToFontFiles to reference separate font files, Embed to include font data in the SVG, or Vectorize to render only text that uses external fonts as graphics. Verify font licensing before embedding fonts.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation, SVGOptions, SvgExternalFontsHandling
from java.io import FileOutputStream
presentation = Presentation("presentation.pptx")
try:
slide = presentation.getSlides().get_Item(0)
font_modes = [
("slide-with-font-links.svg", SvgExternalFontsHandling.AddLinksToFontFiles),
("slide-with-embedded-fonts.svg", SvgExternalFontsHandling.Embed),
("slide-with-vectorized-external-fonts.svg", SvgExternalFontsHandling.Vectorize),
]
for output_file_name, font_mode in font_modes:
svg_options = SVGOptions()
svg_options.setExternalFontsHandling(font_mode)
svg_stream = FileOutputStream(output_file_name)
try:
slide.writeAsSvg(svg_stream, svg_options)
finally:
svg_stream.close()
finally:
presentation.dispose()
Reduce Embedded Image Size
Use SVGOptions.setPicturesCompression to reduce the resolution of embedded pictures, SVGOptions.setDeletePicturesCroppedAreas to omit cropped source areas, and SVGOptions.setJpegQuality to control JPEG encoding quality. These settings reduce file size at the cost of image fidelity or retained image data.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import PicturesCompression, Presentation, SVGOptions
from java.io import FileOutputStream
presentation = Presentation("presentation.pptx")
try:
svg_options = SVGOptions()
svg_options.setPicturesCompression(PicturesCompression.Dpi150)
svg_options.setDeletePicturesCroppedAreas(True)
svg_options.setJpegQuality(80)
slide = presentation.getSlides().get_Item(0)
svg_stream = FileOutputStream("compressed-slide.svg")
try:
slide.writeAsSvg(svg_stream, svg_options)
finally:
svg_stream.close()
finally:
presentation.dispose()
Control Metafile Rasterization Resolution
SVGOptions.setMetafileRasterizationDpi sets the lower resolution limit for rasterizing metafiles during SVG export. Use it to balance detail and file size when an EMF or WMF image is rasterized. It does not define a global DPI for the SVG or force every object on the slide to become a raster image.
Download metafile-rasterization.pptx, which contains an EMF image with closely spaced diagonal lines. The following example exports its first slide at three rasterization resolutions through Slide.writeAsSvg. All other export settings remain identical so that the results can be compared.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import PicturesCompression, Presentation, SVGOptions
from java.io import FileOutputStream
presentation = Presentation("metafile-rasterization.pptx")
try:
for dpi in [72, 150, 300]:
svg_options = SVGOptions()
svg_options.setMetafileRasterizationDpi(dpi)
svg_options.setPicturesCompression(PicturesCompression.Dpi330)
svg_options.setJpegQuality(90)
output_file_name = f"slide-{dpi}.svg"
svg_stream = FileOutputStream(output_file_name)
try:
presentation.getSlides().get_Item(0).writeAsSvg(svg_stream, svg_options)
finally:
svg_stream.close()
finally:
presentation.dispose()
In the output, the EMF became one embedded PNG in each SVG. The following measurements are for the supplied presentation; they are not a general formula for converting DPI to pixel dimensions.
| Metafile rasterization DPI | Embedded PNG dimensions | SVG file size (bytes) |
|---|---|---|
| 72 | 1196 × 596 | 170,221 |
| 150 | 2492 × 1242 | 423,149 |
| 300 | 4983 × 2483 | 1,027,169 |
The comparison below shows the same area of the embedded raster at the same enlarged display size. The diagonal lines show visible pixelation at 72 DPI and smoother edges at higher resolutions, while the SVG file grows. Increasing the value does not necessarily improve every detail or change every exported image.

SVGOptions.setPicturesCompression controls image resolution reduction and can mask the effect of changing the metafile rasterization resolution. SVGOptions.setJpegQuality controls JPEG encoding quality, not metafile rasterization resolution.
Assign Stable IDs to Shapes and Text
Use a Python formatting controller registered through jpype.JProxy to assign SvgShape.setId values to shapes and SvgTSpan.setId values to text tspan elements. Assign the proxy with SVGOptions.setShapeFormattingController.
The following controller uses Shape.getOfficeInteropShapeId, which is stable for the lifetime of the shape, and a repeatable counter for its text spans. This makes the generated IDs suitable for post-processing an unchanged presentation.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation, SVGOptions
from java.io import FileOutputStream
class StableSvgIdController:
def __init__(self):
self.current_shape_id = ""
self.text_span_index = 0
def formatShape(self, svg_shape, shape):
self.current_shape_id = f"shape-{shape.getOfficeInteropShapeId()}"
self.text_span_index = 0
svg_shape.setId(self.current_shape_id)
def formatText(self, svg_tspan, portion, text_frame):
svg_tspan.setId(f"{self.current_shape_id}-text-{self.text_span_index}")
self.text_span_index += 1
presentation = Presentation("presentation.pptx")
try:
controller = StableSvgIdController()
proxy = jpype.JProxy("com.aspose.slides.ISvgShapeAndTextFormattingController", inst=controller)
svg_options = SVGOptions()
svg_options.setShapeFormattingController(proxy)
slide = presentation.getSlides().get_Item(0)
svg_stream = FileOutputStream("slide-with-stable-ids.svg")
try:
slide.writeAsSvg(svg_stream, svg_options)
finally:
svg_stream.close()
finally:
presentation.dispose()
Add SVG Event Handlers
In a Python formatting controller, call SvgShape.setEventHandler with a SvgEvent value to add a JavaScript event handler to an exported shape. Register the controller through jpype.JProxy and assign it with SVGOptions.setShapeFormattingController. Define the JavaScript function in the page or SVG document that hosts the result.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation, SVGOptions, SvgEvent
from java.io import FileOutputStream
class SvgEventController:
def formatShape(self, svg_shape, shape):
if shape.getName() == "ActionButton":
svg_shape.setId("action-button")
svg_shape.setEventHandler(SvgEvent.OnClick, "handleShapeClick(event)")
presentation = Presentation("presentation.pptx")
try:
controller = SvgEventController()
proxy = jpype.JProxy("com.aspose.slides.ISvgShapeFormattingController", inst=controller)
svg_options = SVGOptions()
svg_options.setShapeFormattingController(proxy)
slide = presentation.getSlides().get_Item(0)
svg_stream = FileOutputStream("interactive-slide.svg")
try:
slide.writeAsSvg(svg_stream, svg_options)
finally:
svg_stream.close()
finally:
presentation.dispose()
The host page can define the JavaScript function referenced by the handler. Assigning IDs and event handlers enables slide viewers, accessibility enhancements, and other interactive SVG workflows.
FAQ
When should I use SVGOptions.setVectorizeText instead of SvgExternalFontsHandling.Vectorize?
Use SVGOptions.setVectorizeText when all text must be independent of fonts. Use SvgExternalFontsHandling.Vectorize when only text that uses external fonts should be converted to graphics.
What is the best way to make an SVG smaller?
Start by compressing embedded pictures, deleting cropped image areas, and choosing linked font files when the target environment can serve them. Test the result because lower image resolution, lower JPEG quality, and vectorized text each have different quality and size tradeoffs.
Can I modify exported SVG elements after export?
Yes. Assign IDs through a formatting controller, then select the matching SVG elements in your post-processing tool or browser script.