Render Presentation Slides as SVG Images in PHP
Overview
This article explains how to render presentation slides as SVG images using Aspose.Slides. It describes the SVG format and its advantages, including scalability, accessibility, and suitability for web development.
You will learn how to load a presentation file, iterate through its slides, and save each slide as a separate SVG file. The article covers PowerPoint and OpenDocument presentation formats, including PPT, PPTX, ODP, and PPS, and shows how to perform the conversion programmatically with the Presentation class and the writeAsSvg method.
SVG Format
SVG—an acronym for Scalable Vector Graphics—is a standard graphics type or format used to render two-dimensional images. SVG stores images as vectors in XML with details that define their behavior or appearance.
SVG is one of the few formats for images that meets very high standards in these terms: scalability, interactivity, performance, accessibility, programmability, and others. For these reasons, it is commonly used in web development.
You may want to use SVG files when you need to
- print your presentation in a very large format. SVG images can scale up to any resolution or level. You get to resize SVG images as many times as necessary without sacrificing quality.
- use charts and graphs from your slides in different mediums or platforms. Most readers can interpret SVG files.
- use the smallest possible sizes of images. SVG files are generally smaller than their high-resolution equivalents in other formats, especially those formats based on bitmap (JPEG or PNG).
Render a Slide as an SVG Image
Aspose.Slides for PHP via Java allows you to export slides in your presentations as SVG images. Go through these steps to generate SVG images:
- Create an instance of the Presentation class.
- Iterate through all the slides in the presentation.
- Write every slide to its own SVG file through FileOutputStream.
This sample code shows you how to convert PPT to SVG using Aspose.Slides:
$pres = new Presentation("pres.pptx");
try {
for($index = 0; $index < java_values($pres->getSlides()->size()) ; $index++) {
$slide = $pres->getSlides()->get_Item($index);
$fileStream = new Java("java.io.FileOutputStream", "slide-" . $index . ".svg");
try {
$slide->writeAsSvg($fileStream);
} finally {
$fileStream->close();
}
}
} catch (JavaException $e) {
} finally {
if (!java_is_null($pres)) {
$pres->dispose();
}
}
FAQ
Why might the resulting SVG look different across browsers?
Support for specific SVG features is implemented differently by browser engines. SVGOptions parameters help smooth out incompatibilities.
Is it possible to export not only slides but also individual shapes to SVG?
Yes. Any shape can be saved as a separate SVG, which is convenient for icons, pictograms, and reusing graphics.
Can multiple slides be combined into a single SVG (strip/document)?
The standard scenario is one slide → one SVG. Combining several slides into a single SVG canvas is a post-processing step performed at the application level.