Table of Contents

Class DocxToHtmlConverter

Namespace
DocToolkit
Assembly
DocToolkit.dll

Converts a Word (.docx) package to HTML, keeping the structure ExtractText(byte[]) throws away: headings stay headings, tables stay tables. Use ExtractText when flat text is what you want.

The result is a complete HTML document<html><head>…<body> — not a fragment, and there is no option to change that. Embedding the output in a larger page means extracting the body with an HTML parser you already trust; this package will not do it by string surgery on the renderer's output.

The result is self-contained. Images in the source document are embedded as data: URIs, so nothing in the output points at a file that does not exist.

public static class DocxToHtmlConverter
Inheritance
DocxToHtmlConverter
Inherited Members

Methods

Convert(byte[])

Converts the .docx in docx to a complete HTML document.

public static string Convert(byte[] docx)

Parameters

docx byte[]

The document to convert.

Returns

string

Examples

// A complete HTML document, not a fragment, with images embedded as data: URIs so the
// result is self-contained. Extract the body with a parser if you are embedding it.
string html = DocxToHtmlConverter.Convert(docx);

Exceptions

ArgumentNullException

docx is null.

ArgumentException

docx is empty.

DocumentConversionException

The document could not be converted.

ConvertAsync(Stream, CancellationToken)

Reads a .docx from source and returns it as a complete HTML document.

source is read to its end and is not disposed, closed or sought, so it may be forward-only — an HTTP request body, for instance.

public static Task<string> ConvertAsync(Stream source, CancellationToken ct = default)

Parameters

source Stream

The stream the .docx package is read from.

ct CancellationToken

Cancels the read.

Returns

Task<string>

Exceptions

ArgumentNullException

source is null.

ArgumentException

source is not readable or held no bytes.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The document could not be converted.