Nedev.FileConverters.DocxToHtml 0.1.0

dotnet add package Nedev.FileConverters.DocxToHtml --version 0.1.0
                    
NuGet\Install-Package Nedev.FileConverters.DocxToHtml -Version 0.1.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="Nedev.FileConverters.DocxToHtml" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nedev.FileConverters.DocxToHtml" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Nedev.FileConverters.DocxToHtml" />
                    
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 Nedev.FileConverters.DocxToHtml --version 0.1.0
                    
#r "nuget: Nedev.FileConverters.DocxToHtml, 0.1.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.
#:package Nedev.FileConverters.DocxToHtml@0.1.0
                    
#: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=Nedev.FileConverters.DocxToHtml&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Nedev.FileConverters.DocxToHtml&version=0.1.0
                    
Install as a Cake Tool

Nedev.FileConverters.DocxToHtml

High-performance DOCX to HTML converter for .NET 8.0 and .NET Standard 2.1.

Overview

Nedev.FileConverters.DocxToHtml is a high-performance, zero-dependency library for converting Microsoft Word DOCX documents to HTML format. Built for .NET 8.0 and .NET Standard 2.1, it provides a simple yet powerful API for document conversion with comprehensive feature support.

This library integrates with Nedev.FileConverters.Core to provide a unified interface for file conversion across different formats.

Features

  • High-performance streaming XML parsing
  • Async/await support for file operations
  • Comprehensive style support (bold, italic, underline, colors, fonts, etc.)
  • Table rendering with borders, cell spans, and styling
  • Image embedding (base64) support
  • Numbered and bulleted list support
  • Hyperlink support with configurable target behavior
  • Document metadata extraction (title, author, subject, keywords)
  • Configurable HTML output options
  • Zero external dependencies (uses only .NET BCL)
  • CLI tool included for command-line usage

Installation

NuGet Package

Install the main library:

dotnet add package Nedev.FileConverters.DocxToHtml

Install the CLI tool:

dotnet tool install --global Nedev.FileConverters.DocxToHtml.Cli

Project Reference

Add project reference to your .csproj file:

<ItemGroup>
  <ProjectReference Include="path/to/Nedev.FileConverters.DocxToHtml" />
</ItemGroup>

Quick Start

Basic Conversion

using Nedev.FileConverters.DocxToHtml;

// Convert file to HTML string
var html = DocxConverterExtensions.ConvertToHtml("document.docx");
Console.WriteLine(html);

// Convert and save to file
DocxConverterExtensions.ConvertToHtmlFile("input.docx", "output.html");

Using DocxConverter Instance

using var converter = DocxConverter.FromFile("document.docx");

// Access document metadata
var document = converter.ParseDocument();
Console.WriteLine($"Title: {document.Title}");
Console.WriteLine($"Author: {document.Author}");

// Convert to HTML
var html = converter.ToHtml();

// Save as HTML file
converter.SaveAsHtml("output.html");

Async Operations

// Async file loading
await using var converter = await DocxConverter.FromFileAsync("document.docx");
var html = converter.ToHtml();

// Async conversion
var html = await DocxConverterExtensions.ConvertToHtmlAsync("document.docx");

// Async save
await DocxConverterExtensions.ConvertToHtmlFileAsync("input.docx", "output.html");

From Stream

using var stream = File.OpenRead("document.docx");
using var converter = DocxConverter.FromStream(stream);
var html = converter.ToHtml();

CLI Usage

The CLI tool provides a command-line interface for converting DOCX files to HTML.

Installation

dotnet tool install --global Nedev.FileConverters.DocxToHtml.Cli

Commands

# Convert file and output to console
Nedev.FileConverters.DocxToHtml.Cli -i input.docx

# Convert file and save to specified path
Nedev.FileConverters.DocxToHtml.Cli -i input.docx -o output.html

# Generate minimal HTML (no wrapper and styles)
Nedev.FileConverters.DocxToHtml.Cli -i input.docx -o output.html -m

# Generate full HTML document with all features
Nedev.FileConverters.DocxToHtml.Cli -i input.docx -o output.html -f

# Show version information
Nedev.FileConverters.DocxToHtml.Cli -v

Options

Option Alias Description
--input -i Input DOCX file path (required)
--output -o Output HTML file path (optional, prints to console if not specified)
--minimal -m Generate minimal HTML without wrapper and styles
--full -f Generate full HTML document with all features
--version -v Show version information

Configuration Options

Use HtmlRenderOptions to customize the output:

var options = new HtmlRenderOptions
{
    IncludeHtmlWrapper = true,      // Wrap in <!DOCTYPE html><html>...
    IncludeCharset = true,          // Add <meta charset="utf-8">
    IncludeDefaultStyles = true,    // Add default CSS styles
    PreserveEmptyParagraphs = false,
    RenderSectionBreaks = false,    // Render <hr> for section breaks
    RenderPageBreaks = false,       // Render page break divs
    OpenLinksInNewTab = true,       // Add target="_blank" to links
    IncludeListNumbers = false,     // Include list number text
    EmbedImages = true,             // Embed images as base64
    GenerateTableOfContents = false, // Generate table of contents
    UseCssClasses = false,         // Use CSS classes instead of inline styles
    CustomStyles = "body { max-width: 800px; margin: 0 auto; }",
    CustomHeadContent = "<title>My Document</title>"
};

var html = converter.ToHtml(options);

Preset Configurations

// Full HTML document with all features
var html = converter.ToHtml(HtmlRenderOptions.FullDocument);

// Minimal HTML fragment (no wrapper, no styles)
var html = converter.ToHtml(HtmlRenderOptions.Minimal);

// Default configuration
var html = converter.ToHtml(HtmlRenderOptions.Default);

Supported Elements

Text Formatting

  • Bold, Italic, Underline, Strikethrough
  • Font family and size
  • Text and background colors
  • Superscript and subscript
  • Hyperlinks

Paragraphs

  • Headings (h1-h6)
  • Text alignment (left, center, right, justify)
  • Indentation (left, right, first line)
  • Spacing (before, after, line height)

Lists

  • Numbered lists (decimal, alpha, roman)
  • Bulleted lists
  • Multi-level nesting

Tables

  • Cell borders and styling
  • Column and row spans
  • Cell background colors
  • Width and height

Images

  • Embedded as base64
  • Width and height preserved
  • Alt text support

Other

  • Page breaks
  • Section breaks
  • Tabs (converted to em-space)
  • Line breaks

API Reference

DocxConverter

Main converter class with static factory methods:

Method Description
FromFile(string path) Create converter from file path
FromStream(Stream stream) Create converter from stream
FromFileAsync(string path, CancellationToken) Async file loading
FromStreamAsync(Stream stream, CancellationToken) Async stream loading
ParseDocument() Parse and return Document object
ToHtml(HtmlRenderOptions?) Convert to HTML string
SaveAsHtml(string path, HtmlRenderOptions?) Save HTML to file
SaveAsHtmlAsync(string path, HtmlRenderOptions?, CancellationToken) Async save
GetImage(string relationshipId) Get image bytes by ID
GetImageStream(string relationshipId) Get image stream by ID

DocxConverterExtensions

Static convenience methods:

Method Description
ConvertToHtml(string path, HtmlRenderOptions?) Quick file to HTML
ConvertToHtml(Stream stream, HtmlRenderOptions?) Quick stream to HTML
ConvertToHtmlAsync(...) Async versions
ConvertToHtmlFile(string input, string output, HtmlRenderOptions?) File to file
ConvertToHtmlFileAsync(...) Async version

DocxToHtmlConverter

Implements the IFileConverter interface from Nedev.FileConverters.Core for unified conversion:

Method Description
Convert(Stream input) Convert DOCX stream to HTML stream

This converter is automatically discoverable by the ConverterRegistry in Nedev.FileConverters.Core, making it easy to use in applications that support multiple file format conversions.

Project Structure

Nedev.FileConverters.DocxToHtml/
├── src/
│   ├── Nedev.FileConverters.DocxToHtml/          # Main library
│   ├── Nedev.FileConverters.DocxToHtml.Cli/      # CLI tool
│   └── Nedev.FileConverters.DocxToHtml.Tests/    # Test suite
├── Nedev.FileConverters.DocxToHtml.sln            # Solution file
└── README.md

Requirements

  • .NET 8.0 or later
  • .NET Standard 2.1 or later
  • No external dependencies

Packages

Package Version Description
Nedev.FileConverters.DocxToHtml 0.1.0 Main library for DOCX to HTML conversion
Nedev.FileConverters.DocxToHtml.Cli 0.1.0 CLI tool for command-line usage

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues, questions, or contributions, please visit the project repository.

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 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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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
0.1.0 86 3/6/2026