Introduction
PresentationToHtmlConverter is part of the Slidize.Plugins library. It provides a set of methods for converting PowerPoint and OpenDocument presentations into HTML. This includes both default conversion and conversion with custom settings to meet various requirements.
The core functionality is in the Process method. There are different overloads of this method that allow converting files directly from file paths or streams and provide options for customization.
Basic PowerPoint to HTML Conversion
The simplest way to convert a presentation to HTML is to use the Process method with just the input and output file paths. Here is a basic example:
using Slidize;
PresentationToHtmlConverter.Process("presentation.pptx", "presentation.html");
In this example, the Process method takes the path of the input presentation and the desired output HTML file path. The process converts all slides into HTML format, which can then be viewed in any web browser.
Stream-Based Conversion
Another approach is to use streams instead of file paths. This method is particularly useful in web environments where files may not be stored locally.
using Slidize;
using var inputStream = File.OpenRead("presentation.pptx");
using var outputStream = new MemoryStream();
PresentationToHtmlConverter.Process(inputStream, outputStream);
In this example, the Process method accepts input and output streams, providing more flexibility.
Set a Default Font
The DefaultRegularFont property allows you to set a default font to be used if the original font is not available. This helps avoid situations where text in the presentation is displayed incorrectly due to the absence of a specific font on the device. You can use this property to ensure more predictable text rendering.
using Slidize;
var options = new HtmlConverterOptions
{
DefaultRegularFont = "Arial"
};
PresentationToHtmlConverter.Process("presentation.pptx", "presentation.html", options);
Adjust Picture Compression
The PicturesCompression property controls the compression level of images within the HTML document. This property allows you to balance image quality and file size, which is especially important for web environments where optimizing page load times is crucial.
Example of using the PicturesCompression property:
using Slidize;
var options = new HtmlConverterOptions
{
PicturesCompression = PicturesCompressionLevel.Dpi150
};
PresentationToHtmlConverter.Process("presentation.pptx", "presentation.html", options);
Remove Cropped Areas of Images
The DeletePicturesCroppedAreas property determines whether cropped parts of images should be removed. Removing cropped areas helps reduce the size of the output file, which can be useful for optimization. If this property is set to true, only the visible parts of images will be saved in the HTML, and the cropped parts will be removed.
Example of using the DeletePicturesCroppedAreas property:
using Slidize;
var options = new HtmlConverterOptions
{
DeletePicturesCroppedAreas = true
};
PresentationToHtmlConverter.Process("presentation.pptx", "presentation.html", options);
Control JPEG Image Quality
The JpegQuality property allows you to set the quality of JPEG images, ranging from 0 to 100. A value of 0 means minimal quality with maximum compression, while 100 means maximum quality with minimal compression. This property is useful for controlling the balance between image quality and output file size.
Example of using the JpegQuality property:
using Slidize;
var options = new HtmlConverterOptions
{
JpegQuality = 85
};
PresentationToHtmlConverter.Process("presentation.pptx", "presentation.html", options);
Customize Slide View Options
The SlidesViewOptions property allows you to specify how slides will be displayed during export. This can include settings such as exporting slides with notes, comments, or as handouts. Using this property is useful when you need to customize slide appearance in HTML, especially for creating handouts or print versions of a presentation.
Example of using the SlidesViewOptions property to set output as four slides per page in horizontal order:
using Slidize;
var options = new HtmlConverterOptions
{
SlidesViewOptions = new HandoutViewOptions
{
Handout = HandoutViewType.Handouts4Horizontal
}
};
PresentationToHtmlConverter.Process("presentation.pptx", "presentation.html", options);
Handle Different Presentation Formats
PresentationToHtmlConverter supports various formats, including PowerPoint files (.pptx, .ppt) and OpenDocument files (.odp). Below is an example demonstrating the conversion of an OpenDocument presentation:
using Slidize;
PresentationToHtmlConverter.Process("presentation.odp", "presentation.html");
This simple conversion uses default settings, making it ideal when custom settings are not required.
Practical Use Cases
Embedding presentations on websites: By converting presentations to HTML, you can easily embed them on a website without relying on third-party services. The presentation will be displayed directly in the user's browser.
Creating interactive previews: The HTML version of a presentation can be used to provide a preview to users before they download or view the full version. Web-based presentation tools: You can use PresentationToHtmlConverter to create an online presentation platform where users upload their presentations, and they are displayed in HTML format.