Home | Product Page | Docs | NuGet Package | Demos | API Reference | Blog | Free Support | Temporary License
High-performance .NET API for working with HTML, MHTML, EPUB, Markdown, and SVG – convert, render, edit, and automate web content using C#.
Aspose.HTML for .NET is a developer-friendly library that makes it easy to load, create, parse, convert, and render HTML, MHTML, and SVG content inside any .NET application. The .NET API works as a headless browser, allowing you to create or open existing HTML documents from various sources to perform operations such as removing and replacing HTML nodes, saving and converting HTML documents, extracting CSS from HTML, configuring a document sandbox, and much more. This library provides you with all the tools you need.
- Programmatic DOM manipulation – create, navigate, modify, and remove HTML elements in C#.
- Load documents from file, URL, stream, or string.
- Navigate through document either by NodeIterator or TreeWalker.
- MutationObserver to watch over DOM modifications.
- High-fidelity HTML rendering engine with CSS, JS, fonts, and media support.
- Control the timeout of rendering process.
- Convert HTML to many popular formats including PDF, DOCX, XPS and images.
- Populate HTML document with external data (XML & JSON).
- Support of single (PDF, XPS) or multiple (image formats) output file streams.
- Extract CSS styling information.
- Configuring Sandbox for the environment independent of the execution machine.
Run the following command in the Package Manager Console in Visual Studio to fetch the NuGet package:
Install-Package Aspose.HtmlIf you already have Aspose.HTML for .NET installed and want to update to the latest version, please execute
Update-Package Aspose.HtmlThis example demonstrates how to convert HTML to PDF in just one line of C#. It shows the simplest way to transform dynamic HTML content into a high-quality PDF document using Aspose.HTML for .NET.
using Aspose.Html.Converters;
using Aspose.Html.Saving;
// Convert HTML to PDF using C#
Converter.ConvertHTML(@"<h1>Convert HTML to PDF!</h1>", ".", new PdfSaveOptions(), "convert-with-single-line.pdf");Convert inline SVG code into a PNG image programmatically. A great starting point for generating charts, icons, and dynamic graphics in .NET applications.
using Aspose.Html.Converters;
using Aspose.Html.Saving;
// Prepare SVG code
string code = "<svg xmlns='http://www.w3.org/2000/svg'><circle cx='100' cy='100' r='60' fill='none' stroke='red' stroke-width='10' /></svg>";
// Prepare a path to save the converted file
string savePath = Path.Combine(OutputDir, "circle.png");
// Create an instance of the ImageSaveOptions class
ImageSaveOptions options = new ImageSaveOptions();
// Convert SVG to PNG
Converter.ConvertSVG(code, ".", options, savePath);A practical illustration of DOM manipulation in .NET: create nodes, append content, and build HTML structure dynamically. Ideal for automated content generation or templating.
// Create an instance of an HTML document
using (HTMLDocument document = new HTMLDocument())
{
HTMLElement body = document.Body;
// Create a paragraph element
HTMLParagraphElement p = (HTMLParagraphElement)document.CreateElement("p");
// Set a custom attribute
p.SetAttribute("id", "my-paragraph");
// Create a text node
Text text = document.CreateTextNode("my first paragraph");
// Attach the text to the paragraph
p.AppendChild(text);
// Attach the paragraph to the document body
body.AppendChild(p);
// Save the HTML document to a file
string outPath = Path.Combine(OutputDir, "edit-document-tree.html");
document.Save(outPath);
}This repository works hand in hand with the official Aspose.HTML for .NET documentation. The documentation includes structured guides, conceptual explanations, and step-by-step tutorials, along with a set of practical code samples covering both common and unconventional scenarios you might encounter in real-world .NET projects.
The examples provided here are intended to complement the documentation, extend it, and provide ready-to-use code snippets for converting HTML to PDF, rendering SVG, working with the DOM, processing MHTML, and more.
We warmly welcome contributions that help improve this repository and make the examples even more valuable for the community. To contribute, please follow this simple workflow:
- Create a Feature Branch. Open a new branch for your changes using the feature/* naming pattern. This keeps contributions organized and easy to review.
- Submit a Pull Request. Once your update is ready, open a pull request. It will be automatically routed to the appropriate reviewer for evaluation and feedback.
- Merge After Approval. When your pull request is approved, it will be merged into the repository. Thank you for helping us improve the project!
Home | Product Page | Docs | NuGet Package| Demos | API Reference | Blog | Free Support | Temporary License