![]() |
VOOZH | about |
dotnet add package Aspose.HTML --version 26.5.0
NuGet\Install-Package Aspose.HTML -Version 26.5.0
<PackageReference Include="Aspose.HTML" Version="26.5.0" />
<PackageVersion Include="Aspose.HTML" Version="26.5.0" />Directory.Packages.props
<PackageReference Include="Aspose.HTML" />Project file
paket add Aspose.HTML --version 26.5.0
#r "nuget: Aspose.HTML, 26.5.0"
#:package Aspose.HTML@26.5.0
#addin nuget:?package=Aspose.HTML&version=26.5.0Install as a Cake Addin
#tool nuget:?package=Aspose.HTML&version=26.5.0Install as a Cake Tool
๐ Version 26.5.0
๐ NuGet
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.
The library provides a comprehensive set of features for working with HTML documents:
<style> blocks, and external stylesheets within HTML documents.-aspose- prefixed CSS properties to access advanced rendering and styling features provided by the Aspose.HTML engine, going beyond standard CSS3 capabilities.| 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 | โ๏ธ |
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+).
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.
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
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
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
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?
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
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 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 4 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 |
|
|
HSystem.HIS.Common
Package description |
|
|
ProyectoBaseTemplate
Proyecto Base para colsa |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 26.5.0 | 2,206 | 5/27/2026 |
| 26.4.0 | 7,915 | 4/24/2026 |
| 26.3.0 | 7,159 | 3/20/2026 |
| 26.2.0 | 4,689 | 2/27/2026 |
| 26.1.0 | 14,639 | 1/29/2026 |
| 25.12.0 | 25,396 | 12/22/2025 |
| 25.11.0 | 18,946 | 11/29/2025 |
| 25.10.0 | 3,964 | 11/12/2025 |
| 25.9.0 | 24,960 | 9/26/2025 |
| 25.8.0 | 55,149 | 8/27/2025 |
| 25.7.0 | 15,986 | 7/23/2025 |
| 25.6.0 | 93,954 | 6/19/2025 |
| 25.5.0 | 21,722 | 5/15/2025 |
| 25.4.0 | 37,976 | 4/2/2025 |
| 25.3.0 | 56,451 | 3/5/2025 |
| 25.2.0 | 15,824 | 2/18/2025 |
| 25.1.0 | 20,271 | 1/31/2025 |
| 24.12.0 | 57,054 | 12/26/2024 |
| 24.11.0 | 66,586 | 11/29/2024 |
| 24.10.0 | 45,946 | 10/31/2024 |