Convert PowerPoint Presentations to HTML in Python

Overview

Enhance your workflow by converting PowerPoint presentations to HTML with Aspose.Slides. This guide provides detailed instructions, robust code examples, and tested methods to help you perform reliable and efficient conversions optimized for web viewing.

Aspose.Slides provides many options—primarily through the HtmlOptions class—that control how PowerPoint content is exported to HTML. You can use them to:

  • Export an entire PowerPoint presentation to HTML.
  • Save a specific slide as HTML.
  • Include presentation media, such as images and videos, in the HTML output.
  • Generate responsive HTML from a PowerPoint presentation.
  • Include or exclude speaker notes.
  • Include or exclude comments.
  • Preserve original fonts or use embedded fonts.
  • Export HTML using the new CSS style.

Convert PowerPoint to HTML

Using Aspose.Slides, you can convert an entire PowerPoint presentation to HTML this way:

  1. Create an instance of the Presentation class
  2. Use the Save method to save the object as an HTML file.

This code shows you how to convert a PowerPoint to HTML in python:

import aspose.slides as slides

# Instantiate a Presentation object that represents a presentation file
pres = slides.Presentation("Convert_HTML.pptx")

options = slides.export.HtmlOptions()

options.notes_comments_layouting.notes_position = slides.export.NotesPositions.BOTTOM_FULL
options.html_formatter = slides.export.HtmlFormatter.create_document_formatter("", False)

# Saving the presentation to HTML
pres.save("ConvertWholePresentationToHTML_out.html", slides.export.SaveFormat.HTML, options)

Convert PowerPoint to Responsive HTML

Aspose.Slides provides the ResponsiveHtmlController class that allows you to generate responsive HTML files. This code shows you how to convert a PowerPoint presentation to responsive HTML in python:

# Instantiate a Presentation object that represents a presentation file
import aspose.slides as slides

pres = slides.Presentation("Convert_HTML.pptx")

controller = slides.export.ResponsiveHtmlController()
htmlOptions = slides.export.HtmlOptions()
htmlOptions.html_formatter = slides.export.HtmlFormatter.create_custom_formatter(controller)

# Saving the presentation to HTML
pres.save("ConvertPresentationToResponsiveHTML_out.html", slides.export.SaveFormat.HTML, htmlOptions)

Convert PowerPoint to HTML with Notes

This code shows you how to convert a PowerPoint to HTML with notes in python:

import aspose.slides as slides

pres = slides.Presentation("Presentation.pptx")

opt = slides.export.HtmlOptions()
opt.notes_comments_layouting.notes_position = slides.export.NotesPositions.BOTTOM_FULL

pres.save("Output.html", slides.export.SaveFormat.HTML, opt)

Convert PowerPoint to HTML with Original Fonts

Aspose.Slides provides the EmbedAllFontsHtmlController class that allows you to embed all the fonts in a presentation while converting the presentation to HTML.

To prevent certain fonts from being embedded, you can pass an array of font names to a parameterized constructor from the EmbedAllFontsHtmlController class. Popular fonts, such as Calibri or Arial, when used in a presentation, do not have to be embedded because most systems already contain such fonts. When those fonts are embedded, the resulting HTML document becomes unnecessarily large.

The EmbedAllFontsHtmlController class supports inheritance and provides the WriteFont method, which is meant to be overwritten.

import aspose.slides as slides

pres = slides.Presentation("input.pptx")

# exclude default presentation fonts
fontNameExcludeList = ["Calibri", "Arial"]

htmlOptionsEmbed = slides.export.HtmlOptions()
htmlOptionsEmbed.html_formatter = slides.export.HtmlFormatter.create_custom_formatter(slides.export.EmbedAllFontsHtmlController(fontNameExcludeList))

pres.save("input-PFDinDisplayPro-Regular-installed.html", slides.export.SaveFormat.HTML, htmlOptionsEmbed)

Convert Slide to HTML

Convert a separate presentation slide to HTML. For that use the same Save method exposed by the Presentation class that is used to convert the whole PPT(X) presentation into a HTML document. The HtmlOptions class can be also used to set the additional conversion options:

# [TODO[not_supported_yet]: python implementation of .net interface]

Save CSS and Images When Exporting To HTML

Using new CSS style files, you can easily change the style of the HTML file resulting from the PowerPoint to HTML conversion process.

The python code in this example shows you how to use overridable methods to create a custom HTML document with a link to a CSS file:

# [TODO[not_supported_yet]: python implementation of .net interfaces]

If you do not want to embed fonts (to avoid increasing the size of the resulting HTML), you can link all fonts by implementing your own LinkAllFontsHtmlController version.

This python code shows you how to convert a PowerPoint to HTML while linking all fonts and excluding “Calibri” and “Arial” (since they already exist in the system):

# [TODO[not_supported_yet]: python implementation of .net interfaces]

Support of SVG Responsive Property

The code sample below shows how to export a PPT(X) presentation to HTML with the responsive layout:

presentation = slides.Presentation("SomePresentation.pptx")

saveOptions = slides.export.HtmlOptions()
saveOptions.svg_responsive_layout = True

presentation.save("SomePresentation-out.html", slides.export.SaveFormat.HTML, saveOptions)

Export Media Files to HTML file

Using Aspose.Slides for python, you can export media files this way:

  1. Create an instance of of the Presentation class.
  2. Get a reference to the slide.
  3. Add a video to the slide.
  4. Write the presentation as a HTML file.

This python code shows you how to add a video to the presentation and then save it as HTML:

import aspose.slides as slides

# Loading a presentation
presentation = slides.Presentation("Media File.pptx")

path = "C:\\"
fileName = "ExportMediaFiles_out.html"
baseUri = "http://www.example.com/"

controller = slides.export.VideoPlayerHtmlController(path, fileName, baseUri)

htmlOptions = slides.export.HtmlOptions(controller)
svgOptions = slides.export.SVGOptions(controller)

htmlOptions.html_formatter = slides.export.HtmlFormatter.create_custom_formatter(controller)
htmlOptions.slide_image_format = slides.export.SlideImageFormat.svg(svgOptions)

presentation.save(path + "ExportMediaFiles_out.html", slides.export.SaveFormat.HTML, htmlOptions)

FAQ

How can I convert a PowerPoint presentation to HTML using Python?

You can use the Aspose.Slides for Python via .NET library to load PPT, PPTX, or ODP files and convert them to HTML using the save() method with SaveFormat.HTML.

Does Aspose.Slides support converting individual PowerPoint slides to HTML?

Yes, Aspose.Slides allows you to convert either the entire presentation or specific slides to HTML by configuring HtmlOptions accordingly.

Can I generate responsive HTML from PowerPoint presentations?

Yes, with the ResponsiveHtmlController class, you can export your presentation to a responsive HTML layout that adapts to different screen sizes.

Is it possible to include speaker notes or comments in the exported HTML?

Yes, you can configure the HtmlOptions to include or exclude speaker notes and comments when exporting PowerPoint presentations to HTML.

Can I embed fonts when converting a presentation to HTML?

Yes, Aspose.Slides provides the EmbedAllFontsHtmlController class, which allows you to embed fonts or exclude certain fonts to reduce the output file size.

Does the PowerPoint to HTML conversion support media files like videos and audio?

Yes, Aspose.Slides allows exporting media content embedded in slides to HTML using VideoPlayerHtmlController and related configuration classes.

What file formats are supported for conversion to HTML?

Aspose.Slides supports converting PPT, PPTX, and ODP presentation formats to HTML. It also allows saving slide content as SVG and exporting media assets.

Can I avoid embedding fonts to reduce HTML output size?

Yes, you can link commonly available system fonts like Arial or Calibri instead of embedding them, using a custom implementation of the HtmlController.

Is there an online tool to convert PowerPoint to HTML?

Yes, you can try Aspose’s free web tools such as PPT to HTML or PPTX to HTML to convert presentations directly in your browser without writing any code.

Can I use custom CSS styles in the exported HTML file?

Yes, Aspose.Slides allows linking to external CSS files during conversion, enabling you to fully customize the appearance of the resulting HTML content.