> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/microsoft/markitdown/llms.txt
> Use this file to discover all available pages before exploring further.

# DocumentConverterResult

> Result object returned by document converters

The `DocumentConverterResult` class represents the result of converting a document to Markdown. It contains the converted Markdown text and optional metadata.

## Constructor

```python theme={null}
DocumentConverterResult(
    markdown: str,
    *,
    title: Optional[str] = None
)
```

Create a new conversion result.

<ParamField path="markdown" type="str" required>
  The converted Markdown text.
</ParamField>

<ParamField path="title" type="str">
  Optional title of the document. Extracted from the document when available.
</ParamField>

### Example

```python theme={null}
from markitdown import DocumentConverterResult

result = DocumentConverterResult(
    markdown="# Hello World\n\nThis is the content.",
    title="Hello World"
)
```

## Properties

### markdown

```python theme={null}
markdown: str
```

The converted Markdown text.

<ResponseField name="markdown" type="str">
  The full Markdown content generated from the document.
</ResponseField>

#### Example

```python theme={null}
from markitdown import MarkItDown

md = MarkItDown()
result = md.convert("document.pdf")

print(result.markdown)
# Output: # Document Title
#
# Document content...
```

### title

```python theme={null}
title: Optional[str]
```

The optional title of the document.

<ResponseField name="title" type="str | None">
  Document title extracted during conversion, or `None` if no title was found.
</ResponseField>

#### Example

```python theme={null}
result = md.convert("report.docx")

if result.title:
    print(f"Document title: {result.title}")
else:
    print("No title found")
```

### text\_content (deprecated)

```python theme={null}
text_content: str
```

<Warning>
  `text_content` is soft-deprecated. Use `markdown` or `str(result)` instead.
</Warning>

Alias for the `markdown` property. Provided for backward compatibility.

<ResponseField name="text_content" type="str">
  Same as `markdown`. New code should use `markdown` directly.
</ResponseField>

## Methods

### \_\_str\_\_()

```python theme={null}
def __str__() -> str
```

Returns the converted Markdown text. Allows the result object to be used as a string.

<ResponseField name="markdown" type="str">
  The Markdown content.
</ResponseField>

#### Example

```python theme={null}
result = md.convert("document.pdf")

# These are all equivalent:
print(result.markdown)
print(result.text_content)  # deprecated
print(str(result))
print(result)  # Uses __str__
```

## Usage Examples

### Basic Conversion

```python theme={null}
from markitdown import MarkItDown

md = MarkItDown()
result = md.convert("document.docx")

print(f"Title: {result.title}")
print(f"Length: {len(result.markdown)} characters")
print("\nContent:")
print(result.markdown)
```

### Saving to File

```python theme={null}
result = md.convert("presentation.pptx")

with open("output.md", "w", encoding="utf-8") as f:
    f.write(result.markdown)

print(f"Saved {len(result.markdown)} characters to output.md")
```

### Processing Multiple Files

```python theme={null}
import os
from pathlib import Path

md = MarkItDown()
output_dir = Path("markdown_output")
output_dir.mkdir(exist_ok=True)

for file in Path("documents").glob("*.pdf"):
    result = md.convert(file)
    
    # Use title as filename if available
    if result.title:
        output_name = f"{result.title}.md"
    else:
        output_name = file.with_suffix(".md").name
    
    output_path = output_dir / output_name
    output_path.write_text(result.markdown, encoding="utf-8")
    
    print(f"Converted {file} -> {output_path}")
```

### Extracting Metadata

````python theme={null}
def analyze_document(file_path):
    md = MarkItDown()
    result = md.convert(file_path)
    
    # Count various elements
    lines = result.markdown.split('\n')
    headings = [line for line in lines if line.startswith('#')]
    code_blocks = result.markdown.count('```')
    
    return {
        'title': result.title,
        'length': len(result.markdown),
        'lines': len(lines),
        'headings': len(headings),
        'code_blocks': code_blocks // 2  # Open and close
    }

metadata = analyze_document("report.docx")
print(f"Document: {metadata['title']}")
print(f"Length: {metadata['length']} characters")
print(f"Headings: {metadata['headings']}")
print(f"Code blocks: {metadata['code_blocks']}")
````

### Custom Converter Implementation

```python theme={null}
from markitdown import DocumentConverter, DocumentConverterResult
from typing import BinaryIO, Any

class CustomConverter(DocumentConverter):
    def accepts(self, file_stream: BinaryIO, stream_info, **kwargs: Any) -> bool:
        return stream_info.extension == ".custom"
    
    def convert(self, file_stream: BinaryIO, stream_info, **kwargs: Any) -> DocumentConverterResult:
        content = file_stream.read().decode('utf-8')
        
        # Parse custom format
        lines = content.split('\n')
        title = lines[0] if lines else None
        body = '\n'.join(lines[1:]) if len(lines) > 1 else ""
        
        # Generate Markdown
        markdown = f"# {title}\n\n{body}"
        
        # Return result with metadata
        return DocumentConverterResult(
            markdown=markdown,
            title=title
        )
```

## Return Value Processing

### String Operations

```python theme={null}
result = md.convert("file.pdf")

# String methods work directly
if result.markdown.startswith("# "):
    print("Document has a title heading")

# Search for patterns
import re
emails = re.findall(r'\b[\w.-]+@[\w.-]+\.\w+\b', result.markdown)
print(f"Found {len(emails)} email addresses")

# Count words
words = len(result.markdown.split())
print(f"Word count: {words}")
```

### Markdown Processing

```python theme={null}
import markdown
from bs4 import BeautifulSoup

result = md.convert("document.docx")

# Convert Markdown to HTML
html = markdown.markdown(result.markdown)

# Extract plain text
soup = BeautifulSoup(html, 'html.parser')
plain_text = soup.get_text()

print(f"Plain text length: {len(plain_text)} characters")
```

## See Also

* [DocumentConverter](/api/document-converter) - Base class that produces this result
* [MarkItDown.convert()](/api/markitdown#convert) - Primary method that returns this type
* [StreamInfo](/api/stream-info) - Input metadata for converters
