# IDocumentConversionService

Namespace: **Wisej.AI.Services**

Assembly: **Wisej.AI** (3.5.0.0)

Represents a service interface for converting documents from one format to another.

{% tabs %}
{% tab title="C#" %}

```csharp
public interface IDocumentConversionService
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Interface IDocumentConversionService
```

{% endtab %}
{% endtabs %}

Implementations of this interface provide functionality to convert documents that are provided as a stream. This allows for flexibility in handling documents from various sources such as files or network streams.\
Usage of this interface requires specifying the desired output file type and optionally providing metadata for the document being converted.

## Methods

### ![](/files/ptrKjmmRoQB76pvrIqh0) Convert(stream, fileType, metadata, iterator)

Converts a document from a provided stream to plain text.

| Parameter                                     | Type                                                                         | Description                                                                                                            |
| --------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| **stream**                                    | [Stream](https://docs.microsoft.com/dotnet/api/system.io.stream)             | The stream containing the document to be converted. It must be readable and positioned at the start of the document.   |
| **fileType**                                  | [String](https://docs.microsoft.com/dotnet/api/system.string)                | The format of the input *stream* represented as a string. It should be the file type, i.e.: "pdf", "docx", "html", ... |
| **metadata** ![](/files/52BqKf9SltWQ97FbQSBF) | [Metadata](/ai/components/api/embeddings/wisej.ai.embeddings.metadata.md)    | An optional output parameter to receive metadata about the document. If not provided, the default is `null`.           |
| **iterator** ![](/files/52BqKf9SltWQ97FbQSBF) | [Func\<String, String>](https://docs.microsoft.com/dotnet/api/system.func-2) | An optional function to process each page or paragraph or section of the document being converted.                     |

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). An string representing the converted document.

This method reads a document of type *fileType* from the specified *stream* and convert it to an array strings representing either line, paragraphs or pages, depending on the conversion implementation.\
If the *metadata* parameter is provided, this method will output additional information about the document, such as the title, author, subject, pages, etc.\
If the *iterator* parameter is provided, this method will call it for each section of the document it is converting and will use the returned string value to compose the converted text.\
Example usage:

```csharp

using System.IO;

public class DocumentConverter
{
private readonly IDocumentConversionService _conversionService;

public DocumentConverter(IDocumentConversionService conversionService)
{
_conversionService = conversionService;
}

public void ConvertDocument()
{
using (FileStream fileStream = new FileStream("input.docx", FileMode.Open, FileAccess.Read))
{
string convertedDocument = _conversionService.Convert(fileStream, "pdf");
// Use the converted document
}
}
}

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when *stream* or *fileType* is `null`.

## Implemented By

| Name                                                                                                                | Description                                                                                 |
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| [DefaultDocumentConversionService](https://docs.wisej.com/api?q=wisej.ai.services.defaultdocumentconversionservice) | Provides functionality to convert documents from various formats into text representations. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/ai/components/api/services/idocumentconversionservice.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
