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

2016-10-24 08:38:01 Written by  support iceblue
Rate this item
(0 votes)

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<Byte[]> 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#]
using Spire.Presentation;
using System;
using System.Collections.Generic;
using System.IO;
namespace PPTtoSVG
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx");
            Queue<byte[]> 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]
Imports Spire.Presentation
Imports System.Collections.Generic
Imports System.IO
Namespace PPTtoSVG
	Class Program
		Private Shared Sub Main(args As String())
			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
		End Sub
	End Class
End Namespace

Additional Info

  • tutorial_title: Convert PowerPoint Document to SVG Images in C#, VB.NET
Last modified on Tuesday, 30 November 2021 03:02