Table of Contents

Interface IDocToDocxConverter

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

Reads a Word 97-2003 binary document (.doc) and converts it to a .docx package, or reads its text directly. Registered by AddDocToolkit(IServiceCollection, Action<DocToolkitOptions>?).

public interface IDocToDocxConverter

Remarks

Import only — there is no .doc writing, because the underlying library reports native .doc saving as unsupported.

Convert(byte[]) refuses by default when the source holds content a .docx cannot carry, which in practice is any .doc containing a table. See LegacyDocOptions. ExtractText(byte[]) takes no options and never refuses.

Methods

Convert(byte[])

Converts the legacy .doc in doc to a .docx package.

byte[] Convert(byte[] doc)

Parameters

doc byte[]

Returns

byte[]

Exceptions

ArgumentNullException

doc is null.

ArgumentException

doc is empty.

DocumentConversionException

It could not be converted, or it holds content a .docx cannot carry and AllowContentLoss was not set.

Convert(byte[], LegacyDocOptions?)

Converts the legacy .doc in doc to a .docx package.

byte[] Convert(byte[] doc, LegacyDocOptions? options)

Parameters

doc byte[]

The Word 97-2003 binary document to convert.

options LegacyDocOptions

How to treat content the .docx cannot carry. Null means refuse.

Returns

byte[]

Exceptions

ArgumentNullException

doc is null.

ArgumentException

doc is empty.

DocumentConversionException

It could not be converted, or it holds content a .docx cannot carry and AllowContentLoss was not set.

ConvertAsync(Stream, Stream, LegacyDocOptions?, CancellationToken)

Reads a .doc from source and writes the converted .docx to destination. Neither stream is disposed, closed or sought.

Task ConvertAsync(Stream source, Stream destination, LegacyDocOptions? options, CancellationToken ct = default)

Parameters

source Stream

The stream the .doc is read from.

destination Stream

The stream the .docx package is written to.

options LegacyDocOptions

How to treat content the .docx cannot carry. Null means refuse.

ct CancellationToken

Cancels the read and the write.

Returns

Task

Exceptions

ArgumentNullException

Either stream is null.

ArgumentException

source is not readable or held no bytes, or destination is not writable.

OperationCanceledException

ct was cancelled.

DocumentConversionException

It could not be converted.

ConvertAsync(Stream, Stream, CancellationToken)

Reads a .doc from source and writes the converted .docx to destination. Neither stream is disposed, closed or sought.

Task ConvertAsync(Stream source, Stream destination, CancellationToken ct = default)

Parameters

source Stream
destination Stream
ct CancellationToken

Returns

Task

Exceptions

ArgumentNullException

Either stream is null.

ArgumentException

source is not readable or held no bytes, or destination is not writable.

OperationCanceledException

ct was cancelled.

DocumentConversionException

It could not be converted.

ConvertWithReport(byte[], LegacyDocOptions?)

Converts the legacy .doc in doc and reports what the import could not carry across.

ConversionResult<byte[]> ConvertWithReport(byte[] doc, LegacyDocOptions? options = null)

Parameters

doc byte[]
options LegacyDocOptions

Returns

ConversionResult<byte[]>

Exceptions

ArgumentNullException

doc is null.

ArgumentException

doc is empty.

DocumentConversionException

It could not be converted.

ConvertWithReportAsync(Stream, LegacyDocOptions?, CancellationToken)

Converts the legacy .doc in doc and reports what the import could not carry across.

Task<ConversionResult<byte[]>> ConvertWithReportAsync(Stream source, LegacyDocOptions? options = null, CancellationToken ct = default)

Parameters

source Stream

The stream the .doc is read from.

options LegacyDocOptions

How to treat content the .docx cannot carry. Null means refuse.

ct CancellationToken

Cancels the read and the conversion.

Returns

Task<ConversionResult<byte[]>>

The converted package and the report of what the import could not carry across.

Remarks

source is read to its end and is neither disposed, closed nor sought.

The converted bytes come back in the result rather than through a destination stream, unlike ConvertAsync(Stream, Stream, CancellationToken). That is the only shape that mirrors the synchronous member it is named after: the report and the document are one value, and splitting them across a return value and an out-parameter stream would make this the odd member of its own family.

Exceptions

ArgumentNullException

source is null.

ArgumentException

source is not readable or held no bytes.

OperationCanceledException

ct was cancelled.

DocumentConversionException

It could not be converted.

ExtractText(byte[])

Reads the text of the legacy .doc in doc, table cells included.

string ExtractText(byte[] doc)

Parameters

doc byte[]

Returns

string

Exceptions

ArgumentNullException

doc is null.

ArgumentException

doc is empty.

DocumentConversionException

It could not be read.

ExtractTextAsync(Stream, CancellationToken)

Reads a .doc from source and returns its text. source is read to its end and is not disposed, closed or sought.

Task<string> ExtractTextAsync(Stream source, CancellationToken ct = default)

Parameters

source Stream
ct CancellationToken

Returns

Task<string>

Exceptions

ArgumentNullException

source is null.

ArgumentException

source is not readable or held no bytes.

OperationCanceledException

ct was cancelled.

DocumentConversionException

It could not be read.