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" />
<PackageReference Include="PowGrade.FileConverters.HtmlToDocx" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=PowGrade.FileConverters.HtmlToDocx&version=0.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
PowGrade.FileConverters.HtmlToDocx
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>andReadOnlySpan<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
colspanandrowspanstructures. - π’ 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>
Links and Media
<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/rowspansupport 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 honormargin-top/margin-bottom(or shorthand) and insert corresponding Word spacing. Paragraphs now honormargin-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 | Versions 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.
-
net8.0
- System.Drawing.Common (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.