Convert PowerPoint (PPT/PPTX) to HTML in Python
Converting PowerPoint to HTML format helps us to share presentations on the web and ensures wider accessibility. After converting PowerPoint to HTML, the presentation can be viewed on any web browser enabled device without the need to install specific software.
This article will share how convert a PowerPoint file to HTML, or convert a presentation slide to HTML in Python using a third-party library.
Python Library for Converting PowerPoint Files
To use Python to convert PowerPoint to HTML, we need the Spire.Presentation for Python library. It provides different interfaces for developers to perform various operations on PowerPoint presentations without installing Microsoft Office.
The PowerPoint Python library can be installed via the below pip command:
pip install Spire.Presentation
Convert a PowerPoint File to HTML with Python
For the PowerPoint to HTML conversion, simply load a .ppt or .pptx file and then save it as a HTML file using the Presentation.SaveToFile() method.
from spire.presentation.common import *
from spire.presentation import *
# Load a .ppt or .pptx file
ppt = Presentation()
ppt.LoadFromFile("Presentation.pptx")
# Save the file in HTML format
ppt.SaveToFile("ToHTML.html", FileFormat.Html)
ppt.Dispose()
Output:
Convert a Specified Presentation Slide to HTML with Python
If you only need to convert a certain slide to HTML format, you can first get the specified slide via the Presentation.Slides[] property and then convert it to HTML format through the ISlide.SaveToFile() method.
from spire.presentation.common import *
from spire.presentation import *
# Load a .ppt or .pptx file
ppt = Presentation()
ppt.LoadFromFile(("Presentation.pptx"))
# Get the first slide
slide = ppt.Slides[0]
# Save the slide in HTML format
slide.SaveToFile("SlideToHTML.html", FileFormat.Html)
ppt.Dispose()
Output:
The simple code above helps to convert the loaded PowerPoint document to HTML format. By combining Python and the Spire.Presentation library, you can write custom scripts to automate this conversion process.
To remove the evaluation warning message, click to request a 1-month free trial license: