How to Convert PowerPoint Document to SVG Images in C#, VB.NET

SVG, short for scalable vector graphics, is a XML-based file format used to depict two-dimensional vector graphics. As SVG images are defined in XML text lines, they can be easily searched, indexed, scripted, and supported by most of the up to date web browsers. Therefore, office documents are often converted to SGV images for high fidelity viewing. Following sections will introduce how to convert PowerPoint documents to SVG images using Spire.Presentation in C# and VB.NET.

Code Snippet:

Step 1: Initialize an instance of Presentation class and load a sample PowerPoint document to it.

Presentation ppt = new Presentation();
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx");

Step 2: Convert PowerPoint document to byte array and store in a Queue object.

Queue svgBytes = ppt.SaveToSVG();

Step 3: Initialize an instance of the FileStream class with the specified file path and creation mode. Dequeue the data in the Queue object and write to the stream.

int len = svgBytes.Count;
for (int i = 0; i < len; i++)
{
    FileStream fs = new FileStream(string.Format("result" + "{0}.svg", i), FileMode.Create);
    byte[] bytes = svgBytes.Dequeue();
    fs.Write(bytes, 0, bytes.Length);
}

Output:

How to Convert PowerPoint Document to SVG Images in C#, VB.NET

Full Code:

[C#]
Presentation ppt = new Presentation();
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx");
Queue svgBytes = ppt.SaveToSVG();
int len = svgBytes.Count;
for (int i = 0; i < len; i++)
{
    FileStream fs = new FileStream(string.Format("result" + "{0}.svg", i), FileMode.Create);
    byte[] bytes = svgBytes.Dequeue();
    fs.Write(bytes, 0, bytes.Length);
    ppt.Dispose();
}
[VB.NET]
Dim ppt As New Presentation()
ppt.LoadFromFile("C:\Users\Administrator\Desktop\sample.pptx")
Dim svgBytes As Queue(Of Byte()) = ppt.SaveToSVG()
Dim len As Integer = svgBytes.Count
For i As Integer = 0 To len - 1
	Dim fs As New FileStream(String.Format("result" + "{0}.svg", i), FileMode.Create)
	Dim bytes As Byte() = svgBytes.Dequeue()
	fs.Write(bytes, 0, bytes.Length)
	ppt.Dispose()
Next