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
docxbyte[]The document to convert.
Returns
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
docxis null.- ArgumentException
docxis 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
sourceStreamThe stream the .docx package is read from.
ctCancellationTokenCancels the read.
Returns
Exceptions
- ArgumentNullException
sourceis null.- ArgumentException
sourceis not readable or held no bytes.- OperationCanceledException
ctwas cancelled.- DocumentConversionException
The document could not be converted.