HTML Conversion online or via C#
Convert HTML to PDF, XHTML, MHTML, Markdown, XPS, DOCX and Images
How to Convert HTML Using C#
Hypertext markup language HTML is the language of the Web. Currently, most information is present on websites in form of webpages. So converting this HTML-based information into other formats like PDF, XPS, Microsoft® Word, Markdown and image formats is a common scenario.
Aspose.HTML for .NET API
makes the conversion process easier for developers. It loads the file using HTMLDocument class, creates the relevant save options object and uses the
Converter class
relevant conversion method.
Any conversion you want to perform involves loading an HTML document and saving it in the supported format. It can be different scenarios, but it can be made with a few required steps:
- Load an HTML document into a Document object using one of HTMLDocument() constructors. You can load HTML from a file, HTML code, stream, or URL.
- Create a Save Options object.
- Invoke one of the ConvertHTML() methods and pass the required parameters to it.
Online HTML Converter
You can convert HTML with Aspose.HTML for .NET API in real-time. The following C# example demonstrates how to convert an HTML document. Please load a file from a local file system or URL, select the output format and run the example. You will immediately get the result. You can try Free Online Converters here.
using Aspose.Html; using Aspose.Html.Converters; using Aspose.Html.Saving; using var document = new HTMLDocument("{{input lower}}"); {{#if_output 'PDF'}} var options = new PdfSaveOptions(); {{/if_output}} {{#if_output 'MHTML'}} var options = new MHTMLSaveOptions(); {{/if_output}} {{#if_output 'DOCX'}} var options = new DocSaveOptions(); {{/if_output}} {{#if_output 'XPS'}} var options = new XpsSaveOptions(); {{/if_output}} {{#if_output 'MD'}} var options = new MarkdownSaveOptions(); {{/if_output}} {{#if_output 'BMP' 'JPG' 'GIF' 'PNG' 'TIFF'}} var options = new ImageSaveOptions(ImageFormat.{{output param2 camel}}); {{/if_output}} {{#if_output 'BMP' 'JPG' 'GIF' 'PNG' 'TIFF' 'PDF' 'MHTML' 'MD' 'XPS' 'DOCX'}} Converter.ConvertHTML(document, options, "output.{{output lower}}"); {{/if_output}} {{#if_output 'XHTML'}} document.Save("output.xhtml", new HTMLSaveOptions() { DocumentType = HTMLSaveOptions.XHTML }); {{/if_output}}
Conversion functions in the documentation
The main highlight of Aspose.HTML .NET API 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. Please visit the documentation chapter Converting Between Formats to learn more about Aspose.HTML for .NET API conversion features.
Installing Aspose.HTML for .NET library
This library supports parsing of HTML5, CSS3, SVG, and HTML Canvas to construct a Document Object Model (DOM) based on the WHATWG DOM Standard. You can use several ways to install the Aspose.HTML library for .NET on your system:
- Using the NuGet Package Manager GUI.
- Using the Package Manager Console.
- Installing Aspose.HTML for .NET through MSI.
For more details about C# library installation, please refer to Aspose.HTML Documentation .
Other Supported Conversions
You can also convert HTML, XHTML, MHTML, EPUB, Markdown, and SVG files into many other file formats including few listed below: