Aspose.HTML.Drawing 25.5.0

dotnet add package Aspose.HTML.Drawing --version 25.5.0
                    
NuGet\Install-Package Aspose.HTML.Drawing -Version 25.5.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Aspose.HTML.Drawing" Version="25.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aspose.HTML.Drawing" Version="25.5.0" />
                    
Directory.Packages.props
<PackageReference Include="Aspose.HTML.Drawing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Aspose.HTML.Drawing --version 25.5.0
                    
#r "nuget: Aspose.HTML.Drawing, 25.5.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Aspose.HTML.Drawing&version=25.5.0
                    
Install Aspose.HTML.Drawing as a Cake Addin
#tool nuget:?package=Aspose.HTML.Drawing&version=25.5.0
                    
Install Aspose.HTML.Drawing as a Cake Tool

HTML File Processing .NET API

Version 25.5.0 NuGet

banner

Product Page | Docs | Demos | API Reference | Examples | Blog | Releases | Free Support | Temporary License

Aspose.HTML.Drawing for .NET is a cross-platform class library that functions as a headless browser, allowing you to seamlessly integrate it within your own .NET, C#, VB.NET, and ASP.NET applications without relying on third-party software. It provides a comprehensive set of capabilities, including creating, editing, navigating, and saving HTML and HTML-based documents, along with powerful features like format conversion, document merging, form editing, data extraction, and WCAG-compliant accessibility validation. The library fully supports HTML5, CSS3, SVG, and HTML Canvas, building the Document Object Model (DOM) in accordance with the WHATWG standard. Designed for performance and scalability, Aspose.HTML for .NET can efficiently handle large and complex documents and is compatible with Windows, Linux, and macOS. Its API closely mirrors the W3C HTML specification, offering a familiar development experience.

Aspose.HTML for .NET (Drawing) is a recently created component that is identical to Aspose.HTML for .NET, but it utilizes a different graphic backend called Aspose.Drawing instead of System.Drawing.

HTML API Features

The library provides a comprehensive set of features for working with HTML and HTML-bases documents:

Document Manipulation

  • Create, Edit, and Navigate HTML Content. Create, load, and manipulate HTML, XHTML, SVG, or Markdown documents using a rich, DOM-based API that gives you complete control over elements, attributes, and document structure.
  • Open EPUB and MHTML Formats. Open and convert EPUB and MHTML documents with full support for their internal structure and linked resources.
  • Save with All External Resources. Save documents with all linked assets such as CSS, images, JavaScript, and fonts using advanced and flexible saving options.
  • Fine-Grained Node Manipulation. Perform detailed node-level operations like inserting, deleting, replacing, or cloning HTML elements anywhere within the document tree.
  • Custom Environment Configuration. Configure the processing environment by specifying user style sheets, custom font directories, network handlers, and sandboxing options to meet application-specific needs.

Data Extraction

  • DOM Traversal. Use W3C-compliant traversal APIs to navigate the HTML DOM tree, enabling structured access and inspection of content nodes.
  • XPath Queries. Perform fast and accurate XPath queries to find and extract target content ​​from large HTML documents.
  • CSS Selector and JavaScript. Use CSS selector syntax and run JavaScript scripts to dynamically identify and extract specific content from HTML pages.
  • Extract CSS Styling Information. Retrieve and analyze inline styles, embedded <style> blocks, and external stylesheets within HTML documents.
  • Comprehensive Data Extraction. Extract any data from HTML documents, including text, attributes, form values, metadata, hyperlinks, images, and audio/video tags, for content analysis, processing, or editing.

Conversion between Formats and Rendering

  • One-Line Conversion. Convert HTML, XHTML, SVG, MHTML, EPUB, and Markdown to PDF, XPS, DOCX, or image formats (PNG, JPEG, GIF) with a single line of C# code
  • Custom Conversion Settings. Configure rendering settings such as page size, DPI, background color, font directories, stylesheet overrides, script execution, and more to precisely control the output.
  • Markdown Support. Convert HTML to Markdown or vice versa for content migration and Markdown-based workflows.

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. Populate HTML templates with structured data from XML or JSON sources to generate fully formed, data-driven documents with consistent layout and style.
  • 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. Automatically check HTML content against WCAG standards using Aspose.HTML’s built-in AccessibilityValidator and AccessibilityRules to identify potential accessibility barriers.
  • Screen Reader & Contrast Testing. Verify the presence and accuracy of alternative text and ensure sufficient color contrast to ensure your content is accessible to users with visual impairments and meets visual accessibility requirements.
  • Export Validation Results. Save detailed accessibility reports in multiple formats, listing passed and failed criteria, warnings, and actionable recommendations for remediating issues.

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. Monitor and log the duration of each web request during document loading or resource fetching to analyze performance and optimize response times.
  • Custom Scheme Support. Create message handlers to define and process custom URI schemes, enabling seamless access to embedded or virtualized content sources.
  • Network Operation Timeout Control. Configure global or per-request timeouts to prevent long-running operations and handle slow network conditions gracefully.
  • Password-Based Authentication. Add custom handlers to inject basic or token-based authentication headers into HTTP requests, allowing access to restricted or secured web 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 ✔️ ✔️
PDF 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.Drawing 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

Are you ready to give Aspose.HTML.Drawing for .NET a try? Simply execute Install-Package Aspose.Html.Drawing from Package Manager Console in Visual Studio to fetch the NuGet package. If you already have Aspose.HTML.Drawing for .NET and want to upgrade the version, please execute Update-Package Aspose.Html.Drawing to get the latest version.

Aspose.HTML.Drawing for .NET is easy to integrate and fully self-contained, requiring no additional software or external dependencies. For complete installation instructions, usage examples, and API reference, visit the 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 document from a user string directly in your code and saves it to a file:

// Prepare HTML code
string html_code = "<p>Hello, World! I love HTML!</p>";

// Initialize a document from the string variable
using (HTMLDocument document = new HTMLDocument(html_code, "."))
{
    // Save the document to a disk
    document.Save(Path.Combine(OutputDir, "create-from-string.html"));
}

Source - Creating an HTML Document

Convert HTML to GIT-based Markdown (MD) Format

You can convert HTML, XHTML, SVG, EPUB, MHTML, and Markdown to various supported formats. The following snippet demonstrates the conversion from HTML to Markdown based on GitLab Flavored Markdown syntax:

// Prepare an HTML code and save it to the file.
var code = "<h1>Header 1</h1>" +
           "<h2>Header 2</h2>" +
           "<p>Hello, World!!</p>";
System.IO.File.WriteAllText("document.html", code);

// Call ConvertHTML() method to convert HTML to Markdown
Converter.ConvertHTML("document.html", MarkdownSaveOptions.Git, "output.md");

Source - Convert HTML to Markdown

Convert HTML to PDF using PdfSaveOptions

During HTML to PDF conversion, you can customize save options, including the page size, margins, resolution, document protection, and more. The following example demonstrates HTML to PDF conversion while specifying document information:

// Load an HTML document from file or string
using (HTMLDocument document = new HTMLDocument("<h1>Hello, PDF!</h1>", "."))
{
    // Initialize PdfSaveOptions
    PdfSaveOptions options = new PdfSaveOptions();

    // Set PDF document information (metadata)
    options.DocumentInfo.Title = "Sample PDF Title";
    options.DocumentInfo.Author = "Aspose.HTML for .NET";
    options.DocumentInfo.Subject = "HTML to PDF Example";
    options.DocumentInfo.Keywords = "Aspose, HTML, PDF, conversion";

    // Convert HTML to PDF
    Converter.ConvertHTML(document, options, "document.pdf");
}

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 SVG From Website

The following code illustrates how to extract all inline SVG images from a website by selecting <svg> elements and saving them as separate SVG files to a local file system:

// Open a document you want to extract inline SVG images from
using HTMLDocument document = new HTMLDocument("https://products.aspose.com/html/net/");

// Collect all inline SVG images
HTMLCollection images = document.GetElementsByTagName("svg");

for (int i = 0; i < images.Length; i++)
{
    // Save every SVG image to a local file system
    File.WriteAllText(Path.Combine(OutputDir, $"{i}.svg"), images[i].OuterHTML);
}

Source - Extract SVG 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
25.5.0 2,194 a month ago
25.4.0 2,452 3 months ago
25.3.0 1,739 3 months ago
25.2.0 597 4 months ago
25.1.0 2,020 5 months ago
24.12.0 847 6 months ago
24.11.0 714 7 months ago