Convert Presentations to HTML5 in Python

Overview

This article explains how to convert PowerPoint presentations to HTML5 using Aspose.Slides for Python via .NET. It covers basic export, control of shape animations and slide transitions, and comment layout. It also compares HTML5 output with the SVG-based output of standard HTML export.

Export PowerPoint to HTML5

The following example loads a presentation from the working directory and saves it in HTML5 format. It uses the default export settings; the next example shows how to control animation playback explicitly. Replace the input path with the path to your presentation.

import aspose.slides as slides

with slides.Presentation("pres.pptx") as presentation:
    presentation.save("pres.html", slides.export.SaveFormat.HTML5)

To export without playing shape animations or slide transitions, set animate_shapes and animate_transitions to False in Html5Options. These settings are independent, so you can enable one while disabling the other. The example exports the presentation with both types of animation disabled in the generated page.

import aspose.slides as slides

html5_options = slides.export.Html5Options()
html5_options.animate_shapes = False
html5_options.animate_transitions = False

with slides.Presentation("pres.pptx") as presentation:
    presentation.save("pres5.html", slides.export.SaveFormat.HTML5, html5_options)

Export PowerPoint to HTML

The standard HTML export uses a different rendering approach: slide content is represented by SVG inside an HTML page. The following example converts a presentation to an HTML document using this rendering approach.

import aspose.slides as slides

with slides.Presentation("pres.pptx") as presentation:
    presentation.save("pres.html", slides.export.SaveFormat.HTML)

The simplified markup below illustrates the structure of the generated page. The SVG element contains the rendered slide content; the placeholder text represents that content and is not literal export output.

<body>
<div class="slide" name="slide" id="slideslideIface1">
     <svg version="1.1">
         <g> THE SLIDE CONTENT GOES HERE </g>
     </svg>
</div>
</body>

Export PowerPoint to HTML5 Slide View

HTML5 export produces a page for viewing and navigating the presentation slides in a browser. This example enables both animate_shapes and animate_transitions so that the exported slide view can play effects from the source presentation.

Use a presentation that already contains shape animations and slide transitions to see the effect of these settings. Enabling them does not add new effects to slides that have none. After export, open the generated HTML5 document in a browser with its supporting files available.

import aspose.slides as slides

html5_options = slides.export.Html5Options()
html5_options.animate_shapes = True
html5_options.animate_transitions = True

with slides.Presentation("pres.pptx") as presentation:
    presentation.save("HTML5-slide-view.html", slides.export.SaveFormat.HTML5, html5_options)

Convert a Presentation to an HTML5 Document with Comments

You can include existing slide comments in HTML5 output so that readers can see feedback alongside the slide content. The example in this section expects the source presentation to contain comments, as illustrated below. It exports those comments; it does not create new ones.

Two comments on the presentation slide

Assign a NotesCommentsLayoutingOptions object to the slides_layout_options property of Html5Options. Set comments_position to RIGHT from the CommentsPositions enumeration to place the comments to the right of each slide.

The following example exports the presentation to HTML5 with this comment layout. A presentation without comments will have no comment text to display.

import aspose.slides as slides

layout_options = slides.export.NotesCommentsLayoutingOptions()
layout_options.comments_position = slides.export.CommentsPositions.RIGHT

html5_options = slides.export.Html5Options()
html5_options.slides_layout_options = layout_options

with slides.Presentation("sample.pptx") as presentation:
    presentation.save("output.html", slides.export.SaveFormat.HTML5, html5_options)

The image below shows the exported HTML5 document with the comments displayed beside the slide.

The comments in the output HTML5 document

Suppose hyperlinks.pptx contains linked text with a javascript:alert('Hello') target and an ordinary https://example.com/ link. To exclude the JavaScript hyperlink during export, set Html5Options.skip_java_script_links to True. The default is False, so these links are not filtered unless you enable the option.

The following example loads the presentation from the working directory and exports it using Html5Options:

import aspose.slides as slides

html5_options = slides.export.Html5Options()
html5_options.skip_java_script_links = True

with slides.Presentation("hyperlinks.pptx") as presentation:
    presentation.save("filtered-html5.html", slides.export.SaveFormat.HTML5, html5_options)

The exported file omits the JavaScript hyperlink while retaining its text and the ordinary HTTPS link. The source presentation is unchanged.

This option filters JavaScript hyperlinks; it does not remove all scripts or other active content, nor does it guarantee CSP compliance. For example, HTML5 output still includes scripts for slide navigation and animations.

FAQ

Can I control whether object animations and slide transitions will play in HTML5?

Yes, HTML5 export provides separate options to enable or disable shape animations and slide transitions.

Are comments supported, and where can they be placed relative to the slide?

Yes, existing comments can be included in HTML5 output and positioned (for example, to the right of the slide) through layout settings for notes and comments.

Can I skip links that invoke JavaScript for security or CSP reasons?

Yes, the skip_java_script_links setting allows you to skip hyperlinks with JavaScript calls during saving. The default is False. See Exclude JavaScript Hyperlinks During Export for an HTML5 export example and the scope of the filter. This setting does not remove the JavaScript used by the HTML5 viewer for navigation and animations.