Convert PowerPoint to HTML in Python

Overview

This article explains how to convert PowerPoint Presentation in HTML format using Python. It covers the following topics.

  • Convert PowerPoint to HTML in Python
  • Convert PPT to HTML in Python
  • Convert PPTX to HTML in Python
  • Convert ODP to HTML in Python
  • Convert PowerPoint Slide to HTML in Python

Python PowerPoint to HTML

For Python sample code to convert PowerPoint to HTML, please see the section below i.e. Convert PowerPoint to HTML. The code can load number of formats like PPT, PPTX and ODP in Presentation object and save it to HTML format.

About PowerPoint to HTML Conversion

Using Aspose.Slides for Python via .NET, applications and developers can convert a PowerPoint presentation to HTML: PPTX to HTML or PPT to HTML.

Aspose.Slides provides many options (mostly from the HtmlOptions class) that define the PowerPoint to HTML conversion process:

  • Convert an entire PowerPoint presentation to HTML.
  • Convert a specific slide in a PowerPoint presentation to HTML.
  • Convert presentation media (images, videos, etc.) to HTML.
  • Convert a PowerPoint presentation to responsive HTML.
  • Convert a PowerPoint presentation to HTML with speaker notes included or excluded.
  • Convert a PowerPoint presentation to HTML with comments included or excluded.
  • Convert a PowerPoint presentation to HTML with original or embedded fonts.
  • Convert a PowerPoint presentation to HTML while 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)