简体   繁体   中英

How to convert ppt to HTML in C#?

In my website, admin can upload a PPT & on submission, I am in need to convert to html.

I was using OpenXML library for the Word document. I thought the same lib can be used for PPT also. But not finding the method for the same.

namespace OpenXML_Sample
{
 class Program
 {
    static void Main(string[] args)
    {
        ExportHTML.GenerateHTML(@"D:\test.pptx");
        Console.ReadKey();
    }
}

public class ExportHTML
{
    public static XElement GenerateHTML(string filePath)
    {
        try
        {
            byte[] byteArray = File.ReadAllBytes(filePath);
            using (MemoryStream memoryStream = new MemoryStream())
            {
                memoryStream.Write(byteArray, 0, byteArray.Length);
                using (PresentationDocument pptDoc=
                    PresentationDocument.Open(memoryStream, true))
                {
                    HtmlConverterSettings settings = new HtmlConverterSettings()
                    {
                        PageTitle = "My Page Title"
                    };
                   //not accepting pptDoc as parameter,throws compile time error.
                    XElement xHtml = HtmlConverter.ConvertToHtml(pptDoc, settings);
                    var html = xHtml.ToString();
                    File.WriteAllText(@"D:\sample.html", html,Encoding.UTF8);
                    return xHtml;
                }
            }
        }
        catch (Exception ex)
        {

            throw new FileLoadException(ex.InnerException.Message.ToString());
        }

    }


}

}

How do I pass the ppt document to the method to generate the html document of the uploaded ppt file.

Would welcome for any other(free) api as well.

I have used the Aspose library before and I believe it supports what you are wanting to achieve.

A quick search on their forums revealed this post which might suit your needs;

web,

I like to share that Aspose.Slides for .NET supports exporting presentation file to HTML and you don't even need to install MS Office for this on your machine. All you need to do is to use the appropriate functionality in API. Please visit this documentation link for your kind reference. If you still have an issue then please contact us in Aspose.Slides support forum.

I am working as Support developer/ Evangelist at Aspose.

There are some examples of converting in C# with iSpring Platform http://www.ispringsolutions.com/ispring-platform . It isn't tailored for a certain programming language, but it's easy to use it with C#. First of all, there are some examples, and secondly, there's a Code Builder app, so you can set the necessary conversion configuration and use the generated C# code in your app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM