Convert PowerPoint to HTML
May 5, 2012 6 Comments
This post is explain about how to convert ppt file in html pages by asp.net application. A requirement comes like when user will provide ppt with attached set of images and asp.net application needs to convert it in html pages where images needs to find from ppt and save in one folder and attached with html pages, so html page desing looks like same as ppt.
To implement this I have used MS office atomization tool (DCOM). I have added below dll from .net references.
In MS Power Point has inbuild functionality available to : File> Save as Web Pages. So I have used the same functionality by .net code from Powerpoint compenent.
Below are the code I have implemented to achieve this.
string strSourceFile = @"D:\PPT_Presentation.pptx"; //Give the name and path of the HTML file to be generated string strDestinationFile = @"D:\HTML_Presentation.htm"; //Create a PowerPoint Application Object Microsoft.Office.Interop.PowerPoint.Application oApplication = new Microsoft.Office.Interop.PowerPoint.Application(); //Create a PowerPoint Presentation object Microsoft.Office.Interop.PowerPoint.Presentation oPresentation = oApplication.Presentations.Open(strSourceFile); //Call the SaveAs method of Presentaion object and specify the format as HTML oPresentation.SaveAs(strDestinationFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML); //Close the Presentation object oPresentation.Close(); //Close the Application object oApplication.Quit();
So once you will run the application there will be one html file created which you provided as destination file and one folder created with same name at same location with all required supported files.
Requirement to run this code:
Microsoft office should be installed on the system
Microsoft office Power Point DCOM configured with application user with proper access.
Note: Use direct component is not suggested by Microsoft, due to performance and reliability issue.
So to achieve this scenario Microsoft suggests Office open xml format.
Please contact me at firstname.lastname@example.org for more any other information.