HTML Converter | HTML Conversions in C#

HTML (HyperText Markup Language) is the standard markup language for documents created for display in browsers. Known as the language of the web, HTML has evolved with requirements of new information demands to be displayed as part of web pages. The latest variant is known as HTML 5 that gives a lot of flexibility for working with the language. HTML pages are either received from a server, where these are hosted or can be loaded from a local system as well.

The main highlight of Aspose.HTML is a conversion feature. Converting between formats is required for various reasons: to work in a familiar, convenient format or to take advantage of different formats for specific tasks. The Aspose.Html.Converters namespace implements easy access to conversion methods. It provides a wide range of HTML conversions to popular formats, such as PDF, XPS, DOCX, JPEG, PNG, BMP, TIFF, GIF, MHTML, and MD.

Online HTML Converter

You can check the Aspose.HTML API functionality and convert HTML in real-time. First, load an HTML file from your local drive and then run the example. In this example, the save options are set by default. You will immediately receive the conversion result as a separate file.

Code example in C# to convert document formats
Input file
Upload a file you want to convert
Output format
Select the target format

If you want to convert HTML to PNG programmatically, please see the following C# code examples.

How to Convert HTML in C#

This article gives information on the list of supported HTML conversions and how to perform them using the Converter class that groups all low-level conversion operations in a single class to make them comfy and easy to use.

Please take a look over the following C# code snippet that shows the HTML to PNG conversion using the ConvertHTML(document, options, savePath) method.

using System.IO;
using Aspose.Html;
using Aspose.Html.Converters;
using Aspose.Html.Saving;
...        

    // Initialize an HTML document from a file
    using var document = new HTMLDocument(Path.Combine(DataDir, "nature.html"));
    
    // Initialize ImageSaveOptions 
    var options = new ImageSaveOptions();
    
    // Convert HTML to PNG
    Converter.ConvertHTML(document, options, Path.Combine(OutputDir, "nature-output.png"));

The ConvertHTML() method takes as parameters document, options, and savePath and performs the operation. Note: You need to specify the path to the output file in your local file system (savePath). Also, for HTMLDocument(address) constructor, you need to provide the path to a source HTML file on your local file system.