Aspose.HTML
25.6.0
dotnet add package Aspose.HTML --version 25.6.0
NuGet\Install-Package Aspose.HTML -Version 25.6.0
<PackageReference Include="Aspose.HTML" Version="25.6.0" />
<PackageVersion Include="Aspose.HTML" Version="25.6.0" />
<PackageReference Include="Aspose.HTML" />
paket add Aspose.HTML --version 25.6.0
#r "nuget: Aspose.HTML, 25.6.0"
#addin nuget:?package=Aspose.HTML&version=25.6.0
#tool nuget:?package=Aspose.HTML&version=25.6.0
HTML File Manipulation .NET API
Product Page | Docs | Demos | API Reference | Examples | Blog | Releases | Free Support | Temporary License
Aspose.HTML for .NET is a powerful and flexible library that enables .NET developers to integrate advanced HTML processing and rendering capabilities into their applications without relying on third-party software. It supports a wide range of tasks, from creating, editing, navigating, and saving HTML and HTML-based documents to advanced features such as conversion between formats, merging, HTML form manipulation, data extraction, and WCAG accessibility validation. This library supports parsing of HTML5, CSS3, SVG, and HTML Canvas to construct a Document Object Model (DOM) based on the WHATWG Standard. Aspose.HTML for .NET is designed to handle large and complex documents efficiently and runs seamlessly across Windows, Linux, and macOS. The classes and properties of Aspose.HTML for .NET API have similar names as that of W3C HTML specification.
HTML Processing API Features
The library provides a comprehensive set of features for working with HTML documents:
Document Manipulation
- Create, Edit, and Navigate HTML Documents. Create, load, and modify HTML, XHTML, Markdown, or SVG documents with full control over elements, attributes, and structure using a powerful DOM-based API.
- Load EPUB and MHTML file Formats. Open and convert EPUB and MHTML documents with full support for their internal structure and linked resources.
- Save with Linked Resources. Save documents along with all linked resources like CSS, fonts, and images using customizable saving options.
- Node-Level Operations. Insert, remove, clone, or replace HTML elements at any level of the DOM tree for granular control over content.
- Custom Environment Configuration. Set custom user style sheets, font folders, message handlers, sandboxing, and other environment parameters to tailor document rendering and behavior.
Data Extraction
- DOM Traversal. Navigate and manipulate the DOM tree using W3C-compliant traversal interfaces to inspect and retrieve content from HTML documents.
- XPath Queries. Perform high-performance XPath queries to find and extract target content from large HTML documents.
- CSS Selector and JavaScript. Use CSS selector queries and JavaScript execution to dynamically locate and extract specific elements.
- Extract CSS Styling Information. Retrieve and analyze inline styles, embedded
<style>
blocks, and external stylesheets within HTML documents. - Extract any Data from HTML Documents. Text, attributes, form values, metadata, tables, links, or media elements: Aspose.HTML for .NET enables accurate and efficient extraction of any content for processing, analysis, or editing.
Conversion between Formats and Rendering
- Single-line Conversion. Convert HTML, XHTML, SVG, MHTML, MD, and EPUB files to PDF, XPS, DOCX, and image formats like PNG, JPEG, or GIF with a single line of C# code.
- Custom Conversion Settings. Adjust page size, resolution, stylesheets, resource management, script execution, and other settings during conversion to fine-tune the output.
- Markdown Support. Convert HTML to Markdown or vice versa for content migration and Markdown-based workflows.
- Timeout Control. Set time limits for the rendering process to manage resource usage and ensure responsive app performance.
Merging
- Combine HTML Content. Merge multiple HTML, XHTML, MHTML, EPUB or Markdown documents into a single unified file, preserving styles, structure, and referenced resources.
HTML Templates
- Data-Binding with Templates. Convert HTML templates by embedding data from XML or JSON sources to create dynamic and reusable HTML documents.
- Attribute Control in Templates. Programmatically manage the presence and value of HTML attributes during the data-binding process for precise control over the output.
Web Accessibility
- WCAG Compliance Validation. Check web documents against WCAG standards using built-in validators and accessibility rule sets.
- Screen Reader & Contrast Testing. Ensure compatibility with assistive technologies by validating ARIA attributes and checking color contrast levels.
- Multimedia Accessibility Checks. Evaluate multimedia elements to ensure compliance with accessibility guidelines.
- Export Validation Results. Generate reports detailing errors, warnings, and success criteria to help improve your content’s accessibility.
Built-in Formats
- HTML5 Parsing Engine. Accurately parse and render modern HTML5 documents, generating a reliable and standards-compliant DOM tree.
- JavaScript Execution. Execute JavaScript code embedded in HTML documents with support for ECMAScript 5.1 and timeout controls.
- CSS3 Styling. Manipulate stylesheets, inline styles, and computed styles across entire documents or targeted elements using a powerful CSS API.
- HTML Canvas & SVG 2.0 Support. Utilize HTML Canvas elements and render modern SVG features, such as filters and gradients, based on the latest specifications.
Message Handlers
- Web Request Execution Time Logging. Implement a message handler that logs web request durations, helping you monitor performance and identify bottlenecks.
- ZIP Archive Handling. Use a message handler to access and manipulate HTML or resource files directly within ZIP archives without manual extraction.
- Network Operation Timeout Control. Implement a message handler that sets and manages timeouts for web requests, improving reliability and responsiveness in slow or unstable networks.
- Password-Based Authentication. Configure a message handler that automatically adds password-based credentials to HTTP requests for secure access to protected resources.
Advanced HTML Features
- Edit HTML5 Canvas Programmatically. Draw shapes, text, and graphics on HTML5 Canvas using JavaScript or the HTML Canvas API, allowing precise control over visual content directly within your application.
- Stream Output Handling. Redirect HTML rendering output to custom streams, enabling flexible integration with various workflows such as cloud storage, memory-based processing, or secure data pipelines.
- Monitor DOM Changes. Use the MutationObserver interface to detect and respond to changes in the HTML DOM, such as attribute modifications, node insertions, or content updates in real time.
- HTML Form Editor. Programmatically access, modify and submit HTML form elements, including text fields, checkboxes, and buttons. Control form behavior to support automation, validation, and testing scenarios.
- CSS Extensions. Leverage
-aspose-
prefixed CSS properties to access advanced rendering and styling features provided by the Aspose.HTML engine, going beyond standard CSS3 capabilities.
Supported File Formats
Format | Description | Load | Save |
---|---|---|---|
HTML | HyperText Markup Language format | ✔️ | ✔️ |
XHTML | eXtensible HyperText Markup Language format | ✔️ | ✔️ |
MHTML | MIME HTML format | ✔️ | ✔️ |
EPUB | E-book file format | ✔️ | |
SVG | Scalable Vector Graphics format | ✔️ | ✔️ |
MD | Markdown markup language format | ✔️ | ✔️ |
Portable Document Format | ✔️ | ||
XPS | XML Paper Specification format | ✔️ | |
DOCX | Microsoft Word Open XML document format | ✔️ | |
TIFF | Tagged Image File Format | ✔️ | |
JPEG | Joint Photographic Experts Group format | ✔️ | |
PNG | Portable Network Graphics format | ✔️ | |
BMP | Bitmap Picture format | ✔️ | |
GIF | Graphics Interchange Format | ✔️ | |
WEBP | Modern image format providing both lossy and lossless compression | ✔️ |
Platform Independence
Aspose.HTML for .NET is written completely in C# and can be used to build any type of 32-bit or 64-bit .NET application including ASP.NET, WCF, WinForms & .NET Core. Development platforms include all flavors of Windows, Linux, and Mac OS X x64 (10.12+).
Getting Started
To add Aspose.HTML for .NET to your project, run the following command in the Package Manager Console in Visual Studio:
Install-Package Aspose.Html
To update to the latest version, use:
Update-Package Aspose.Html
This ensures you have the most recent features, enhancements, and fixes. For more information and API reference, visit the Aspose.HTML for .NET documentation.
Create an HTML Document
Aspose.HTML for .NET enables you to create HTML documents from scratch as an empty document with an HTML structure, from a string, from a memory stream, or by loading from a file or a URL. The following example creates a new HTML document from scratch and populates it with content:
// Initialize an empty HTML Document
using (HTMLDocument document = new HTMLDocument())
{
HTMLElement body = document.Body;
// Create a heading element <h1> and set its text
HTMLHeadingElement h1 = (HTMLHeadingElement)document.CreateElement("h1");
Text texth1 = document.CreateTextNode("Create HTML file");
// Create a paragraph element set its text
HTMLParagraphElement p = (HTMLParagraphElement)document.CreateElement("p");
Text text = document.CreateTextNode("Learn how to create HTML file");
// Attach the text to the h1 and paragraph
h1.AppendChild(texth1);
p.AppendChild(text);
// Attach h1 and paragraph to the document body
body.AppendChild(h1);
body.AppendChild(p);
// Save the document to a disk
document.Save("create-new-document.html");
}
Source - Creating an HTML Document
Convert Markdown to HTML
You can convert HTML, XHTML, SVG, EPUB, MHTML, and Markdown to various supported formats. The following snippet demonstrates the conversion from Markdown to HTML using just a single line of code:
// Call ConvertMarkdown() method to convert Markdown to HTML
Converter.ConvertMarkdown("document.md", "document.html");
Source - Convert Markdown to HTML
Convert HTML to PDF Using Encryption Property
During HTML to PDF conversion, you can customize save options, including the page size, margins, resolution, document protection, and more. The following example demonstrates converting HTML to PDF with password protection for the document:
// Initialize an HTML document from a URL
using HTMLDocument document = new HTMLDocument("https://docs.aspose.com/html/files/document.html");
// Initialize PdfSaveOptions
PdfSaveOptions options = new PdfSaveOptions();
// Configure PDF encryption settings
options.Encryption = new PdfEncryptionInfo(
ownerPassword: "owner123",
userPassword: "user123",
permissions: PdfPermissions.PrintDocument | PdfPermissions.ExtractContent,
encryptionAlgorithm: PdfEncryptionAlgorithm.RC4_128
);
// Prepare a path to save the converted file
string savePath = Path.Combine(OutputDir, "document-with-password.pdf");
// Convert HTML to PDF
Converter.ConvertHTML(document, options, savePath);
Source - Convert HTML to PDF
Resize Document During Conversion from HTML to PNG
During conversion from HTML, you can use rendering options to resize document pages to match the content size and vice versa. To fit the page width of the output image to the width of the content, you need to use the FitToContentWidth
flag or the FitToWidestContentWidth
flag, which will fit the width of the resulting document to the width of the widest page.
// Create an instance of HTMLDocument class
using HTMLDocument document = new HTMLDocument("rendering.html");
// Initialize an ImageRenderingOptions object with custom options. Use the FitToWidestContentWidth flag
ImageRenderingOptions opt = new ImageRenderingOptions()
{
PageSetup =
{
PageLayoutOptions = PageLayoutOptions.FitToWidestContentWidth
}
};
// Create an output rendering device and convert HTML to PNG
using ImageDevice device = new ImageDevice(opt, "FitWidth.png");
document.RenderTo(device);
Source - How to Resize Document During Conversion from HTML?
Extract Images From Website
You can extract all images from a web page by selecting <img>
elements and saving them as separate files to a local file system:
// Open a document you want to download images from
using HTMLDocument document = new HTMLDocument("https://docs.aspose.com/svg/net/drawing-basics/svg-shapes/");
// Collect all <img> elements
HTMLCollection images = document.GetElementsByTagName("img");
// Create a distinct collection of relative image URLs
IEnumerable<string> urls = images.Select(element => element.GetAttribute("src")).Distinct();
// Create absolute image URLs
IEnumerable<Url> absUrls = urls.Select(src => new Url(src, document.BaseURI));
foreach (Url url in absUrls)
{
// Create an image request message
using RequestMessage request = new RequestMessage(url);
// Extract image
using ResponseMessage response = document.Context.Network.Send(request);
// Check whether a response is successful
if (response.IsSuccess)
{
// Save image to a local file system
File.WriteAllBytes(Path.Combine(OutputDir, url.Pathname.Split('/').Last()), response.Content.ReadAsByteArray());
}
}
Source - Extract Images From Website
Check Web Accessibility
The following C# code snippet demonstrates the basic steps for creating a validator, loading an HTML document, and validating it for WCAG accessibility compliance:
// Initialize a webAccessibility container
WebAccessibility webAccessibility = new WebAccessibility();
// Create an accessibility validator
AccessibilityValidator validator = webAccessibility.CreateValidator();
// Initialize an HTMLDocument object
using (HTMLDocument document = new HTMLDocument("document.html"))
{
// Check the document
ValidationResult result = validator.Validate(document);
// Checking for success
if (!result.Success)
{
foreach (RuleValidationResult detail in result.Details)
{
// ... do the analysis here...
Console.WriteLine("{0}:{1} = {2}", detail.Rule.Code, detail.Rule.Description, detail.Success);
}
}
}
Source - Web Accessibility – How to Check in C#
Product Page | Docs | Demos | API Reference | Examples | Blog | Releases | Free Support | Temporary License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.0)
- System.Diagnostics.DiagnosticSource (>= 7.0.0)
- System.Drawing.Common (>= 4.7.3)
- System.Numerics.Vectors (>= 4.5.0)
- System.Security.Permissions (>= 4.5.0)
- System.Text.Encoding.CodePages (>= 4.5.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Aspose.HTML:
Package | Downloads |
---|---|
Aspose.Total
Aspose.Total for .NET is the most complete package of all .NET file format APIs offered by Aspose. It empowers developers to create, edit, render, print and convert between a wide range of popular document formats within any .NET, C#, ASP.NET and VB.NET applications. |
|
CHOCore.Tools
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
25.6.0 | 261 | 6/19/2025 |
25.5.0 | 4,919 | 5/15/2025 |
25.4.0 | 9,741 | 4/2/2025 |
25.3.0 | 11,888 | 3/5/2025 |
25.2.0 | 7,691 | 2/18/2025 |
25.1.0 | 6,813 | 1/31/2025 |
24.12.0 | 21,348 | 12/26/2024 |
24.11.0 | 31,902 | 11/29/2024 |
24.10.0 | 23,276 | 10/31/2024 |
24.9.0 | 30,475 | 9/25/2024 |
24.8.0 | 34,693 | 8/29/2024 |
24.7.0 | 31,097 | 7/31/2024 |
24.6.0 | 43,388 | 6/21/2024 |
24.5.0 | 28,086 | 5/3/2024 |
24.4.0 | 9,018 | 4/12/2024 |
24.3.0 | 59,644 | 3/18/2024 |
24.2.0 | 12,425 | 2/27/2024 |
24.1.0 | 103,066 | 1/11/2024 |
23.12.0 | 23,474 | 12/5/2023 |
23.11.0 | 46,428 | 11/3/2023 |
23.10.0 | 74,519 | 10/6/2023 |
23.9.0 | 55,094 | 9/5/2023 |
23.8.1 | 185,364 | 8/11/2023 |
23.7.0 | 26,466 | 7/12/2023 |
23.6.0 | 26,235 | 6/29/2023 |
23.5.0 | 44,096 | 5/3/2023 |
23.4.0 | 35,571 | 4/4/2023 |
23.3.0 | 96,417 | 3/10/2023 |
23.2.0 | 65,746 | 2/1/2023 |
23.1.0 | 60,065 | 1/20/2023 |
22.11.0 | 179,378 | 11/22/2022 |
22.10.0 | 50,742 | 10/28/2022 |
22.9.0 | 28,881 | 10/1/2022 |
22.8.0 | 85,461 | 8/19/2022 |
22.7.0 | 21,579 | 7/30/2022 |
22.6.0 | 23,393 | 6/28/2022 |
22.5.0 | 73,730 | 5/19/2022 |
22.4.0 | 45,825 | 4/19/2022 |
22.3.0 | 144,169 | 3/7/2022 |
22.2.0 | 39,841 | 2/11/2022 |
22.1.0 | 33,286 | 1/13/2022 |
21.12.0 | 22,955 | 12/8/2021 |
21.11.0 | 37,077 | 11/1/2021 |
21.10.0 | 15,151 | 10/9/2021 |
21.9.0 | 37,394 | 9/2/2021 |
21.8.0 | 60,115 | 8/4/2021 |
21.7.0 | 59,715 | 7/1/2021 |
21.6.0 | 11,843 | 6/9/2021 |
21.5.0 | 16,045 | 5/20/2021 |
21.4.0 | 25,500 | 5/1/2021 |
21.3.0 | 31,828 | 3/10/2021 |
21.2.0 | 80,845 | 2/4/2021 |
21.1.0 | 412,349 | 1/14/2021 |
20.12.0 | 29,436 | 12/4/2020 |
20.11.0 | 41,433 | 11/3/2020 |
20.9.0 | 27,061 | 9/30/2020 |
20.8.0 | 23,348 | 8/31/2020 |
20.7.0 | 10,474 | 7/28/2020 |
20.6.0 | 11,850 | 6/30/2020 |
20.5.0 | 49,722 | 5/20/2020 |
20.4.0 | 41,641 | 4/3/2020 |
20.3.0 | 102,703 | 3/12/2020 |
20.2.0 | 14,585 | 2/9/2020 |
20.1.0 | 8,989 | 1/14/2020 |
19.12.0 | 20,059 | 12/4/2019 |
19.11.0 | 16,815 | 11/11/2019 |
19.10.0 | 22,067 | 10/8/2019 |
19.9.0 | 18,514 | 9/6/2019 |
19.8.0 | 8,732 | 8/7/2019 |
19.7.0 | 9,446 | 7/8/2019 |
19.6.0 | 5,946 | 6/10/2019 |
19.5.0 | 16,877 | 5/9/2019 |
19.4.0 | 11,705 | 4/5/2019 |
19.3.0 | 35,854 | 3/5/2019 |
19.2.0 | 6,502 | 2/6/2019 |
19.1.0 | 3,711 | 1/9/2019 |
18.12.0 | 10,927 | 12/7/2018 |
18.11.0 | 12,287 | 11/6/2018 |
18.10.0 | 3,149 | 10/5/2018 |
18.9.0 | 13,927 | 9/5/2018 |
18.8.0 | 3,441 | 8/7/2018 |
18.7.0 | 3,311 | 7/5/2018 |
18.6.0 | 3,236 | 6/6/2018 |
18.5.0 | 5,807 | 5/2/2018 |
18.4.0 | 3,224 | 4/6/2018 |
18.3.0 | 13,846 | 3/6/2018 |
18.2.0 | 4,851 | 2/7/2018 |
18.1.0 | 15,425 | 1/11/2018 |
17.12.0 | 2,657 | 12/4/2017 |
17.11.0 | 2,517 | 11/9/2017 |
17.10.0 | 2,378 | 10/9/2017 |
17.9.0 | 2,606 | 9/8/2017 |
17.8.0 | 2,504 | 8/10/2017 |
17.7.0 | 9,599 | 7/14/2017 |