DocumentConverter 1.0.5

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

DocumentConverter

DocumentConverter is a powerful document converter library that supports HTML to PDF, XLSX, and DOCX conversion, as well as PDF, XLS, XLSX, DOC, and DOCX to HTML conversion. It provides a simple and efficient API for transforming documents between popular formats while preserving content and structure.

NuGet Version License: MIT


Key Features

  • 🔄 Bidirectional Conversion:
    • Document ➔ HTML: Convert legacy/modern Word, Excel, and PDF files into structured HTML.
    • HTML ➔ Document: Convert HTML content back into fully formatted .docx, .xlsx, or .pdf files.
  • 🐧 100% Cross-Platform & Linux Ready: Completely decoupled from native OS dependencies like GDI+ or System.Drawing.Common for metadata lookup. Run it anywhere without Unix-compatibility workarounds.
  • 🖼️ Advanced Image Processing:
    • Resolves Base64 Data URIs, local file paths, and remote HTTP/HTTPS image URLs (using a thread-safe, cancellation-supported downloader).
    • Preserves cell-relative image alignments in PDF and Excel (anchors images exactly inside their source table cells and auto-scales row heights to prevent overlapping content).
  • ⚡ Performance & Memory Optimized:
    • Implements Registry Pattern for extensibility.
    • Cell Style Caching for NPOI Excel sheets to prevent Excel style limit exhaustion.
    • Efficient backtracking StringBuilder text-wrapping for PDF generation.

Installation

Install the package via NuGet:

dotnet add package DocumentConverter

Usage Examples

1. Convert Office Documents to HTML

Initialize the DocumentConverterService and perform conversions via file paths or streams:

using DocumentConverter;
using DocumentConverter.Models;

var service = new DocumentConverterService();

// Option A: Convert from a file path
Result<string> pathResult = service.ConvertToHtml("report.docx");
if (pathResult.IsSuccess)
{
    string html = pathResult.Value;
    File.WriteAllText("report.html", html);
}

// Option B: Convert from a stream (ideal for web uploads/downloads)
using (var stream = File.OpenRead("data.xlsx"))
{
    Result<string> streamResult = service.ConvertToHtml(stream, ".xlsx");
    if (streamResult.IsSuccess)
    {
        string htmlTable = streamResult.Value;
    }
}

2. Convert HTML back to Office Documents (Bytes or File)

You can convert HTML back to Word, Excel, or PDF documents. The library will write the file directly or return the raw bytes:

using DocumentConverter;
using DocumentConverter.Models;

var service = new DocumentConverterService();
string htmlContent = "<h1>Document Title</h1><p>This is a paragraph.</p>";

// Option A: Convert HTML and save directly to a file
Result<bool> fileResult = service.ConvertFromHtml(htmlContent, ".pdf", "output.pdf");
if (fileResult.IsSuccess)
{
    Console.WriteLine("PDF file generated successfully!");
}

// Option B: Convert HTML and retrieve the raw bytes
Result<byte[]> bytesResult = service.ConvertFromHtml(htmlContent, ".docx");
if (bytesResult.IsSuccess)
{
    byte[] docxBytes = bytesResult.Value;
    File.WriteAllBytes("output.docx", docxBytes);
}

Supported Formats Matrix

Format Document Type Document ➔ HTML HTML ➔ Document Engine / Parser
.doc Legacy Word (97-2003) NPOI / HWPF
.docx Modern Word (OpenXML) NPOI / XWPF
.xls Legacy Excel (97-2003) NPOI / HSSF
.xlsx Modern Excel (OpenXML) NPOI / XSSF
.pdf PDF Document UglyToad.PdfPig / PdfSharpCore

Contributing & Extensibility

Adding a new document format converter is simple. The service implements a Registry Pattern. You can register custom converters in DocumentConverterService by matching the IDocumentConverter (for Document ➔ HTML) and IHtmlToDocumentConverter (for HTML ➔ Document) interfaces.


License

This project is licensed under the MIT 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
1.0.5 0 6/19/2026
1.0.4 0 6/19/2026
1.0.3 6 6/19/2026
1.0.2 48 6/17/2026
1.0.1 45 6/17/2026
1.0.0 43 6/17/2026