Table of Contents

Interface IHtmlToDocxConverter

Namespace
DocToolkit.Extensions.DependencyInjection
Assembly
DocToolkit.Extensions.DependencyInjection.dll

Converts HTML to a Word (.docx) package. Registered by AddDocToolkit(IServiceCollection, Action<DocToolkitOptions>?); remote image download is controlled once, at registration, via AllowRemoteImageDownload, and bounded by RemoteImage.

public interface IHtmlToDocxConverter

Methods

ConvertAsync(string, PageSetup, Stream, CancellationToken)

As above, laid out on page rather than the A4 default.

Task ConvertAsync(string html, PageSetup page, Stream destination, CancellationToken ct = default)

Parameters

html string

The markup to convert.

page PageSetup

The page size, orientation and margins.

destination Stream

The stream the result is written to.

ct CancellationToken

Cancels the conversion and the write.

Returns

Task

Exceptions

ArgumentNullException

Any argument is null.

ArgumentException

destination is not writable.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The HTML could not be converted.

ConvertAsync(string, PageSetup, CancellationToken)

As above, laid out on page rather than the A4 default.

Task<byte[]> ConvertAsync(string html, PageSetup page, CancellationToken ct = default)

Parameters

html string

The markup to convert.

page PageSetup

The page size, orientation and margins.

ct CancellationToken

Cancels the conversion.

Returns

Task<byte[]>

Exceptions

ArgumentNullException

html or page is null.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The HTML could not be converted.

ConvertAsync(string, Stream, CancellationToken)

Converts html and writes the .docx to destination. destination is written, from its current position, and is not disposed, closed or sought.

Task ConvertAsync(string html, Stream destination, CancellationToken ct = default)

Parameters

html string
destination Stream
ct CancellationToken

Returns

Task

Exceptions

ArgumentNullException

html or destination is null.

ArgumentException

destination is not writable.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The HTML could not be converted or written.

ConvertAsync(string, CancellationToken)

Converts html to the bytes of a .docx package.

Task<byte[]> ConvertAsync(string html, CancellationToken ct = default)

Parameters

html string
ct CancellationToken

Returns

Task<byte[]>

Exceptions

ArgumentNullException

html is null.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The HTML could not be converted.