Convert PowerPoint to HTML
May 5, 2012 4 Comments
Hello friends,
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.
Microsfot.Office.Core
Microsfot.Office.Interop.PowerPoint
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.
http://support.microsoft.com/kb/257757/en-us
So to achieve this scenario Microsoft suggests Office open xml format.
http://msdn.microsoft.com/en-us/library/bb332059(v=office.12).aspx
Please contact me at amitpatel.it@gmail.com for more any other information.
Thanks,
Amit Patel
“Enjoy Programming”
You can write this in single line as given bellow.
new Microsoft.Office.Interop.PowerPoint.Application().oApplication.Presentations.Open(strSourceFile).oPresentation.SaveAs(strDestinationFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML);
Write this simple code for this
POWERPOINT.Application App = new Microsoft.Office.Interop.PowerPoint.Application();
POWERPOINT.Presentation pres = App.Presentations.Open(fileName, OFFICECORE.MsoTriState.msoTrue, OFFICECORE.MsoTriState.msoFalse, OFFICECORE.MsoTriState.msoFalse);
int pageNo = 0;
pres.SaveAs(imagePath + “\Images”, POWERPOINT.PpSaveAsFileType.ppSaveAsPNG, OFFICECORE.MsoTriState.msoFalse);
//you need to add references and namespaces as
using POWERPOINT = Microsoft.Office.Interop.PowerPoint;
using OFFICECORE = Microsoft.Office.Core;
Thanks for comment,
We can use this code for in my post I have explained about covert those all in html.
is there any code in php to convert ppt to html