Introduction
Converting slides from PowerPoint and OpenDocument presentations into SVG images is a common requirement for embedding presentations on web pages or enhancing compatibility across different applications. In this article, we will explore how to achieve this using the PresentationToSvgConverter
class from the Slidize.Plugins library. We will look at several examples demonstrating different presentation conversion scenarios, including customizing SVG output using available options.
The PresentationToSvgConverter
class is a plugin within the Slidize.Plugins library designed to convert PowerPoint 97-2003 and Microsoft Office Open XML presentations into SVG (Scalable Vector Graphics) images. SVG is a popular format for rendering vector graphics on the web, offering flexibility and scalability without loss of image quality. This converter helps transform slides into SVG format with various configuration options for controlling the output.
Basic PowerPoint to SVG Conversion
Let's start with a simple example to convert a PowerPoint presentation to SVG format without any additional options. This method takes the input presentation and creates SVG images for each slide.
using Slidize;
PresentationToSvgConverter.Process("presentation.pptx", "image.svg");
In this example, we specify the path to the input presentation (presentation.pptx
) and an output path template (image.svg
) where the SVG images will be saved.
Set a Default Regular Font
The SvgConverterOptions
class provides a DefaultRegularFont
property, which allows you to specify a default font to be used if the original font is unavailable. This helps ensure consistency in the SVG output, especially when the original presentation uses custom fonts that may not be accessible.
using Slidize;
var options = new SvgConverterOptions
{
DefaultRegularFont = "Arial"
};
PresentationToSvgConverter.Process("presentation.pptx", "image.svg", options);
In this example, DefaultRegularFont
is set to "Arial", which will be used as a fallback font if the original font cannot be found during the conversion process.
Manage the Compression Level of Pictures
The SvgConverterOptions
class also provides a PicturesCompression
property, which allows you to control the compression level of pictures within the generated SVG document. This can help reduce the size of the SVG file, making it more efficient for web use or other scenarios where file size is important.
using Slidize;
var options = new SvgConverterOptions
{
PicturesCompression = PicturesCompressionLevel.Dpi150
};
PresentationToSvgConverter.Process("presentation.pptx", "image.svg", options);
In this example, PicturesCompression
is set to Dpi150
, providing good compression while maintaining reasonable image quality. This option is especially useful when optimizing SVG for use on web pages with limited bandwidth.
Vectorize Text for Improving Text Quality
The SvgConverterOptions
class includes a VectorizeText
property that allows you to convert text into vector paths. This is useful for improving text quality when scaling and ensuring sharpness regardless of zoom level.
using Slidize;
var options = new SvgConverterOptions
{
VectorizeText = true
};
PresentationToSvgConverter.Process("presentation.pptx", "image.svg", options);
In this example, VectorizeText
is set to true
, ensuring that all text in the presentation is converted to vector paths, making the text sharper regardless of the zoom level.
Adjust JPEG Quality in the SVG
The SvgConverterOptions
class also provides a JpegQuality
property, which allows you to adjust the quality of JPEG images embedded in the SVG. This can help achieve a balance between image quality and file size.
using Slidize;
var options = new SvgConverterOptions
{
JpegQuality = 85
};
PresentationToSvgConverter.Process("presentation.pptx", "image.svg", options);
In this example, JpegQuality
is set to 85
, allowing a balance between image quality and file size. This setting can be very useful when specific control over the output SVG quality is needed.
Control the Resolution of Rasterized Metafiles
The SvgConverterOptions
class also provides a MetafileRasterizationDpi
property, which controls the resolution used when rasterizing any metafiles present in the presentation. This option is useful when you need to ensure high-quality rendering of graphics initially embedded as metafiles.
using Slidize;
var options = new SvgConverterOptions
{
MetafileRasterizationDpi = 150
};
PresentationToSvgConverter.Process("presentation.pptx", "image.svg", options);
In this example, MetafileRasterizationDpi
is set to 150
, ensuring high-quality rasterization of metafiles in the presentation.