DocumentConverter 1.0.5
Prefix Reserveddotnet add package DocumentConverter --version 1.0.5
NuGet\Install-Package DocumentConverter -Version 1.0.5
<PackageReference Include="DocumentConverter" Version="1.0.5" />
<PackageVersion Include="DocumentConverter" Version="1.0.5" />
<PackageReference Include="DocumentConverter" />
paket add DocumentConverter --version 1.0.5
#r "nuget: DocumentConverter, 1.0.5"
#:package DocumentConverter@1.0.5
#addin nuget:?package=DocumentConverter&version=1.0.5
#tool nuget:?package=DocumentConverter&version=1.0.5
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.
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.pdffiles.
- 🐧 100% Cross-Platform & Linux Ready: Completely decoupled from native OS dependencies like GDI+ or
System.Drawing.Commonfor 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 | Versions 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. |
-
.NETStandard 2.0
- HtmlAgilityPack (>= 1.12.4)
- NPOI (>= 2.5.6)
- PdfSharpCore (>= 1.3.67)
- ScratchPad.NPOI.HWPF (>= 2.5.7)
- SixLabors.ImageSharp (>= 2.1.13)
- System.Drawing.Common (>= 10.0.9)
- System.Text.Encoding.CodePages (>= 10.0.9)
- UglyToad.PdfPig (>= 1.7.0-custom-5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.