> For the complete documentation index, see [llms.txt](https://docs.wisej.com/ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wisej.com/ai/components/api/services/idocumentconversionservice/wisej.ai.services.defaultdocumentconversionservice.md).

# DefaultDocumentConversionService

Namespace: **Wisej.AI.Services**

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

Provides functionality to convert documents from various formats into text representations.

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

```csharp
public class DefaultDocumentConversionService : IDocumentConversionService
```

{% endtab %}

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

```visual-basic
Public Class DefaultDocumentConversionService
    Inherits IDocumentConversionService
```

{% endtab %}
{% endtabs %}

This class implements the [IDocumentConversionService](/ai/components/api/services/idocumentconversionservice.md) interface and provides methods to convert documents from streams into text arrays. Supported formats include PDF, DOCX, and HTML. The conversion process can also include metadata extraction if provided.

## Constructors

### ![](/files/ptrKjmmRoQB76pvrIqh0) DefaultDocumentConversionService()

Initializes a new instance of [DefaultDocumentConversionService](https://docs.wisej.com/api?q=wisej.ai.services.defaultdocumentconversionservice).

## Methods

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

Converts a document from a given stream into a specified file type.

| 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)    | Optional metadata related to the document conversion. Defaults to null.                                                |
| **iterator** ![](/files/52BqKf9SltWQ97FbQSBF) | [Func\<String, String>](https://docs.microsoft.com/dotnet/api/system.func-2) | 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). A string representing the 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.\
Example usage:

```csharp

using (var fileStream = File.OpenRead("example.docx"))
{
var conversionService = new DefaultDocumentConversionService();
string convertedDocumentPath = conversionService.Convert(fileStream, "pdf");
Console.WriteLine($"Document converted and saved to: {convertedDocumentPath}");
}

```

* Ensure the stream is positioned at the beginning or the correct position for reading.
* Supported file types should be verified with the service documentation.
* Handle potential exceptions that may arise from invalid streams or unsupported file types.**Throws:**
* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when *stream* or *fileType* is null.

## Implements

| Name                                                                                    | Description                                                                         |
| --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| [IDocumentConversionService](/ai/components/api/services/idocumentconversionservice.md) | Represents a service interface for converting documents from one format to another. |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
