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
docbyte[]
Returns
- byte[]
Exceptions
- ArgumentNullException
docis null.- ArgumentException
docis 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
docbyte[]The Word 97-2003 binary document to convert.
optionsLegacyDocOptionsHow to treat content the .docx cannot carry. Null means refuse.
Returns
- byte[]
Exceptions
- ArgumentNullException
docis null.- ArgumentException
docis 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
sourceStreamThe stream the .doc is read from.
destinationStreamThe stream the .docx package is written to.
optionsLegacyDocOptionsHow to treat content the .docx cannot carry. Null means refuse.
ctCancellationTokenCancels the read and the write.
Returns
Exceptions
- ArgumentNullException
Either stream is null.
- ArgumentException
sourceis not readable or held no bytes, ordestinationis not writable.- OperationCanceledException
ctwas 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
sourceStreamdestinationStreamctCancellationToken
Returns
Exceptions
- ArgumentNullException
Either stream is null.
- ArgumentException
sourceis not readable or held no bytes, ordestinationis not writable.- OperationCanceledException
ctwas 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
docbyte[]optionsLegacyDocOptions
Returns
Exceptions
- ArgumentNullException
docis null.- ArgumentException
docis 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
sourceStreamThe stream the .doc is read from.
optionsLegacyDocOptionsHow to treat content the .docx cannot carry. Null means refuse.
ctCancellationTokenCancels 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
sourceis null.- ArgumentException
sourceis not readable or held no bytes.- OperationCanceledException
ctwas 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
docbyte[]
Returns
Exceptions
- ArgumentNullException
docis null.- ArgumentException
docis 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
sourceStreamctCancellationToken
Returns
Exceptions
- ArgumentNullException
sourceis null.- ArgumentException
sourceis not readable or held no bytes.- OperationCanceledException
ctwas cancelled.- DocumentConversionException
It could not be read.