PowGrade.FileConverters.HtmlToDocx 0.1.3

dotnet add package PowGrade.FileConverters.HtmlToDocx --version 0.1.3
                    
NuGet\Install-Package PowGrade.FileConverters.HtmlToDocx -Version 0.1.3
                    
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="PowGrade.FileConverters.HtmlToDocx" Version="0.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PowGrade.FileConverters.HtmlToDocx" Version="0.1.3" />
                    
Directory.Packages.props
<PackageReference Include="PowGrade.FileConverters.HtmlToDocx" />
                    
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 PowGrade.FileConverters.HtmlToDocx --version 0.1.3
                    
#r "nuget: PowGrade.FileConverters.HtmlToDocx, 0.1.3"
                    
#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.
#:package PowGrade.FileConverters.HtmlToDocx@0.1.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PowGrade.FileConverters.HtmlToDocx&version=0.1.3
                    
Install as a Cake Addin
#tool nuget:?package=PowGrade.FileConverters.HtmlToDocx&version=0.1.3
                    
Install as a Cake Tool

PowGrade.FileConverters.HtmlToDocx

.NET 10 License: MIT NuGet

High-performance HTML to DOCX converter built on .NET 10 with zero third-party dependencies. Achieves high-fidelity conversion through a custom CSS engine and robust OpenXML generation.

✨ Features

  • πŸš€ Extreme Performance - Zero-allocation parsing using Span<T> and ReadOnlySpan<char>.
  • πŸ“¦ Zero Dependencies - Pure .NET implementation, no third-party libraries (no OpenXML SDK).
  • 🎨 Full CSS Engine - Custom cascading style resolution supporting <style> blocks and inline attributes. Handles comma‑separated selector lists, descendant ( ) and child (>) combinators, class/ID/compound selectors, and proper inheritance.
  • πŸ“Š Advanced Tables - Sophisticated grid mapping for complex colspan and rowspan structures.
  • πŸ”’ Nested Lists - Support for multi-level <ul> and <ol> with correct numbering indentation.
  • πŸ–ΌοΈ Multimedia - Automatic embedding of local, remote (HTTP/S), and Base64 data URI images with automatic dimension detection.
  • πŸ“ Page Layout - Configurable page size (A4, Letter, etc.) and margins.
  • πŸ“„ Headers & Footers - HTML <header> and <footer> mapped to Word header/footer parts.
  • πŸ”’ Page Numbering - Dynamic PAGE / NUMPAGES fields.
  • πŸ“– Table of Contents - Auto-generated TOC field from headings.

πŸ“¦ Installation

NuGet Package

dotnet add package PowGrade.FileConverters.HtmlToDocx

CLI Tool

dotnet tool install --global PowGrade.FileConverters.HtmlToDocx.Cli

πŸš€ Quick Start

Basic Usage

using PowGrade.FileConverters.HtmlToDocx;

// Simple conversion
string html = "<h1>Hello World</h1><p>This is a test.</p>";
byte[] docxBytes = html.ToDocx();
File.WriteAllBytes("output.docx", docxBytes);

// Using service with options
var options = new ConverterOptions { PageWidth = 11906, PageHeight = 16838 }; // A4
using var service = new HtmlToDocxService(options);
byte[] result = service.Convert(html);

Async Conversion

byte[] asyncResult = await html.ToDocxAsync();

βš™οΈ Configuration Options

var options = new ConverterOptions
{
    PreserveStyles = true,           // Enable CSS engine
    DownloadImages = true,           // Download remote images
    MaxImageSize = 10 * 1024 * 1024, // 10MB
    PageWidth = 11906,               // A4 Width
    Margins = new PageMargins { Top = 1440, Bottom = 1440 }
};

πŸ“‹ Supported HTML Elements

Text & Formatting

  • <p>, <h1>~<h6>, <br>, <hr>, <span>, <div>
  • <strong>/<b>, <em>/<i>, <u>, <s>, <font>
  • <a> - Hyperlinks with relationship management.
  • <img> - Supports .jpg, .png, .gif (local, remote, base64).

Lists

  • <ul> (Bullet) and <ol> (Numbered) with nested levels.

Tables

  • <table>, <thead>, <tbody>, <tr>, <th>, <td>.
  • Full colspan / rowspan support with grid stabilization.

🎨 Supported CSS Properties

  • Typography: color (hex, rgb/rgba/hsl/hsla/transparent/named), font-size (pt/px/em/rem/%), font-family, font-weight, font-style, text-decoration, text-align.
    Paragraphs now honor margin-top/margin-bottom (or shorthand) and insert corresponding Word spacing. Paragraphs now honor margin-top/margin-bottom (or shorthand) and insert corresponding Word spacing.
  • Layout: width, height, margin (page-level), padding, background-color (parsing only).
  • Inheritance: Styles correctly cascade from parent containers to text runs; inheritable properties include font and color settings.

⚑ Performance

Verified performance on .NET 10:

File Size Conversion Time Throughput
10 KB ~3 ms 3,300 chars/ms
100 KB ~15 ms 6,600 chars/ms
1 MB ~120 ms 8,300 chars/ms

Test environment: Intel i7-12700, Windows 11, .NET 10.0

πŸ—οΈ Architecture

PowGrade.FileConverters.HtmlToDocx/
β”œβ”€β”€ Html/           # Span-based HTML Tokenizer & Tree Builder
β”œβ”€β”€ Css/            # Custom CSS Parser & Cascade Resolver
β”œβ”€β”€ Docx/           # OpenXML (WordprocessingML) Generator
β”œβ”€β”€ Models/         # Shared Converter & Layout Models
β”œβ”€β”€ Utils/          # ZipArchiveHelper & IO Utilities
└── HtmlToDocxService.cs 

πŸ“ Roadmap

Medium Priority

  • SVG to EMF conversion support

Low Priority

  • MathML support
  • RTF export support

πŸ“„ License

MIT License - see LICENSE file for details

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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
0.1.3 155 6/9/2026
0.1.2 123 6/7/2026
0.1.1 117 5/24/2026
0.1.0 119 4/30/2026